Bug 13023 – optimizer produces wrong code for comparision and division of ulong

Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
All
Creation time
2014-07-02T17:22:00Z
Last change time
2014-08-22T08:05:00Z
Keywords
pull, wrong-code
Assigned to
yebblies
Creator
simon.buerger

Comments

Comment #0 by simon.buerger — 2014-07-02T17:22:09Z
The following code fails when compiling with -O on a 64-bit system. Note that the problem does not appear when removing the writefln() or not passing n as a parameter. Using long instead of ulong solves the problem as well. import std.stdio; void foo(ulong n) { ulong k = 0; writefln("%s", k>=n/2); // correctly print 'false' if(k>=n/2) // triggers with -O assert(false); } void main() { ulong n = (1UL<<32)*2; foo(n); }
Comment #1 by safety0ff.bugz — 2014-07-15T22:59:08Z
This looks like another REX issue, dmd is comparing 4 bytes instead of 8 against zero. The lower 4 bytes of (1UL<<32)*2/2 are all zero.
Comment #2 by yebblies — 2014-07-24T14:40:39Z
Comment #3 by github-bugzilla — 2014-07-24T22:51:03Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/1fced8b109eb74b03adc232ca6057c2235505049 Fix Issue 13023 - optimizer produces wrong code for comparision and division of ulon https://github.com/D-Programming-Language/dmd/commit/f79c6c576bae0a14edc4b4eb67134f753f7a7b8b Merge pull request #3809 from yebblies/issue13023 Issue 13023 - optimizer produces wrong code for comparision and division of ulong
Comment #4 by github-bugzilla — 2014-07-24T22:57:15Z
Commit pushed to dmd-1.x at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/1c85734dad8e5704105c37603a694bac34925095 Fix Issue 13023 - optimizer produces wrong code for comparision and division of ulon
Comment #5 by github-bugzilla — 2014-07-31T02:35:14Z
Commit pushed to 2.066 at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/780325cc7b58ed22fdddbeac20cc6a0d957cb28c Merge pull request #3809 from yebblies/issue13023 Issue 13023 - optimizer produces wrong code for comparision and division of ulong
Comment #6 by github-bugzilla — 2014-08-22T08:05:00Z