[Issue 16189] Optimizer bug, with simple test case

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Feb 7 15:20:07 UTC 2018


https://issues.dlang.org/show_bug.cgi?id=16189

Seb <greensunny12 at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |greensunny12 at gmail.com

--- Comment #5 from Seb <greensunny12 at gmail.com> ---
See also the discussion in the forum:
https://forum.dlang.org/post/jguphfhffgtdtfittkyw@forum.dlang.org

My summary:

The optimizer seems to be confused and wrongly precomputes a.
Note that if you remove e.g. "if (b) goto loop;", a will be correctly
statically set in the printf too:

---
                mov     RSI,0FFFFFFFFh                ; look ma - a is now -1
                lea     RDI,FLAT:.rodata[00h][RIP]
                xor     EAX,EAX                       ; set eax to 0
                call      printf at PLT32
---

For comparison the assembly of -O.
Here with printf and a different value to be compared with a because it's
easier to read:

---
main:
                push    RBP
                mov     RBP,RSP
                sub     RSP,010h
                lea     RAX,-010h[RBP]
                xor     ECX,ECX
                mov     [RAX],RCX
                mov     8[RAX],CL
                lea     RSI,-010h[RBP]
                lea     RDI,-010h[RBP]
                movsd
                movsb
                mov     RSI,01C71C71C71C71C70h          ; 2 function argument
(value of a)
                lea     RDI,FLAT:.rodata[00h][RIP]      ; "%d" (1st function
argument)
                xor     EAX,EAX                         ; set eax to 0
                call      printf at PLT32                  ; printf("%d", a)
                mov     EDX,0Ch
                lea     RSI,_TMP0 at PC32[RIP]             ; load function
arguments (in reverse order)
                lea     RDI,_TMP0 at PC32[RIP]
                call      __assert at PLT32                ; values load, let's
call assert
                add     [RAX],AL
.text.main      ends
        end
----

--


More information about the Digitalmars-d-bugs mailing list