[Issue 15573] -O -inline causes wrong code with idiv instruction

2016-03-21 Thread via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=15573

--- Comment #34 from github-bugzi...@puremagic.com ---
Commit pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/30ec03499244697e8c691c29e058c76d1571c4ec
Merge pull request #5559 from yebblies/issue15573

--


[Issue 15573] -O -inline causes wrong code with idiv instruction

2016-03-20 Thread via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=15573

--- Comment #33 from github-bugzi...@puremagic.com ---
Commit pushed to stable at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/30ec03499244697e8c691c29e058c76d1571c4ec
Merge pull request #5559 from yebblies/issue15573

Issue 15573 - -O -inline causes wrong code with idiv instruction

--


[Issue 15573] -O -inline causes wrong code with idiv instruction

2016-03-20 Thread via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=15573

--- Comment #32 from github-bugzi...@puremagic.com ---
Commits pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/6210867ef1024bf29d5b0342cf31dd511380a24a
Fix Issue 15573 - -O -inline causes wrong code with idiv instruction

https://github.com/D-Programming-Language/dmd/commit/766073e4740983906505ebbff9a833d5fe713081
Merge pull request #5559 from yebblies/issue15573

Issue 15573 - -O -inline causes wrong code with idiv instruction

--


[Issue 15573] -O -inline causes wrong code with idiv instruction

2016-03-20 Thread via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=15573

yebblies  changed:

   What|Removed |Added

   Keywords||pull
 OS|Linux   |All

--- Comment #31 from yebblies  ---
Found it: https://github.com/D-Programming-Language/dmd/pull/5559

--


[Issue 15573] -O -inline causes wrong code with idiv instruction

2016-03-20 Thread via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=15573

--- Comment #30 from yebblies  ---
(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.

--


[Issue 15573] -O -inline causes wrong code with idiv instruction

2016-01-21 Thread via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=15573

--- Comment #28 from yebblies  ---
(In reply to hsteoh from comment #27)
> Argh you're right, I missed that... that'll teach me to analyze assembly
> code without stepping through it in a debugger...

Honestly I didn't know that instruction existed until I looked at this code. 
If you can find the actual error let me know.

--


[Issue 15573] -O -inline causes wrong code with idiv instruction

2016-01-21 Thread via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=15573

--- Comment #29 from hst...@quickfur.ath.cx ---
Alright, I think I found the real culprit now.

Still referencing the asm dump I posted, the problematic spot is here:

...
  438cb8:   31 f6   xor%esi,%esi
  438cba:   64 48 8b 0c 25 00 00mov%fs:0x0,%rcx
  438cc1:   00 00
  438cc3:   48 8b 15 66 91 24 00mov0x249166(%rip),%rdx#
681e30 <_DYNAMIC+0x258>
  438cca:   89 34 11mov%esi,(%rcx,%rdx,1)
* PROBLEM: rdx at this point contains -288 (0xfee0)
  438ccd:   38 75 f8cmp%dh,-0x8(%rbp)
  438cd0:   41 0f 94 c6 sete   %r14b
...

I'm not exactly sure what exactly is the load from 0x249166(%rip) for, or why
the compiler would want to emit such a thing here, because this part of the
code is computing the value of "(right == 0)" (from the top of the safeDiv
function, here inlined). The corresponding part of the good (unoptimized)
version of the code reads:

... (NOTE: from a different disassembly)
  438bb1:   89 7d f0mov%edi,-0x10(%rbp)
  438bb4:   89 75 f8mov%esi,-0x8(%rbp)
// right == 0
  438bb7:   80 7d f0 00 cmpb   $0x0,-0x10(%rbp)
  438bbb:   0f 94 c0sete   %al
...

Here, %edi contains the parameter 'right', which is stored in the local stack
variable -0x10(%rbp) and then compared against 0.

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.

--


[Issue 15573] -O -inline causes wrong code with idiv instruction

2016-01-21 Thread via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=15573

--- Comment #27 from hst...@quickfur.ath.cx ---
Argh you're right, I missed that... that'll teach me to analyze assembly code
without stepping through it in a debugger...

--


[Issue 15573] -O -inline causes wrong code with idiv instruction

2016-01-21 Thread via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=15573

yebblies  changed:

   What|Removed |Added

 CC||yebbl...@gmail.com

--- Comment #26 from yebblies  ---
Are you sure that's where it's going wrong?

This line
438d18:   99  cltd   

Is sign extending AX -> DX:AX which appears to be correct, no?

--


[Issue 15573] -O -inline causes wrong code with idiv instruction

2016-01-20 Thread via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=15573

--- Comment #24 from hst...@quickfur.ath.cx ---
Maybe related?: https://issues.dlang.org/show_bug.cgi?id=10540

--


[Issue 15573] -O -inline causes wrong code with idiv instruction

2016-01-20 Thread via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=15573

--- Comment #25 from thomas.bock...@gmail.com ---
The similar crashes I was getting with LDC turn out to be unrelated to this
issue, despite the similar symptoms:
https://issues.dlang.org/show_bug.cgi?id=15586
(It's a bug in Phobos, which I have already submitted a PR for.)

--


[Issue 15573] -O -inline causes wrong code with idiv instruction

2016-01-19 Thread via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=15573

hst...@quickfur.ath.cx changed:

   What|Removed |Added

Summary|mystery crashes in @safe|-O -inline causes wrong
   |code|code with idiv instruction

--