[Issue 16268] Wrong optimization in code with integer overflow
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Tue Jul 12 11:17:20 PDT 2016
https://issues.dlang.org/show_bug.cgi?id=16268
Lodovico Giaretta <lodovico at giaretart.net> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |lodovico at giaretart.net
--- Comment #1 from Lodovico Giaretta <lodovico at giaretart.net> ---
Looking at the generated assembly, it looks like, as a check x >= 0 is
performed before entering the loop, the compiler establishes that overflow will
not happen while condition i <= x holds (with x not negative).
Of course this is false for the edge case of x = typeof(x).max.
00 push rbp
01 mov rbp,rsp
04 push rbx
05 push r12
07 mov r12,rdi
0a xor ebx,ebx ; i = 0
0c test r12b,r12b
0f js 21 ; if x < 0 skip for loop
11 movsx edi,bl
15 call <writeln> ; call writeln
1a inc bl ; i++
1c cmp bl,r12b
1f jle 11 ; if i <= x continue for loop
21 pop r12
23 pop rbx
24 pop rbp
25 ret
--
More information about the Digitalmars-d-bugs
mailing list