[Issue 15573] -O -inline causes wrong code with idiv instruction
    via Digitalmars-d-bugs 
    digitalmars-d-bugs at puremagic.com
       
    Sat Mar 19 23:47:25 PDT 2016
    
    
  
https://issues.dlang.org/show_bug.cgi?id=15573
--- Comment #30 from yebblies <yebblies at gmail.com> ---
(In reply to hsteoh from comment #29)
> 
> In the bad (optimized) version at the top, however, it's comparing the local
> variable `m` (which, from an earlier part of the dump, can be seen to be
> stored in -0x8(%rbp)) against %dh, which doesn't seem to make sense. Why
> does the compiler emit a comparison agains %dh instead of 0x0?  Is it
> assuming that %dh is zero? Why would it make such as assumption?
> 
> After this point, the value of div0 is wrong, and the code proceeds down a
> different path than it should.
Yeah, the compiler is incorrectly assuming that dh contains zero.  In cdnot in
cod2.c, there is the check
if (reghasvalue((sz == 1) ? BYTEREGS : ALLREGS,0,®))
which uses the cmp mem, reg form if it finds a register that contains zero. 
I'm not sure why it returns true and sets reg to 6 though.
--
    
    
More information about the Digitalmars-d-bugs
mailing list