https://issues.dlang.org/show_bug.cgi?id=20162
Issue ID: 20162 Summary: Bug in optimization of remainder operation Product: D Version: D2 Hardware: All OS: All Status: NEW Severity: major Priority: P1 Component: dmd Assignee: nob...@puremagic.com Reporter: h...@hos.ac The following code produces weird results: ---- import std.stdio; long f(long a) { return a % 1000000; } void main() { foreach (i; 0 .. 2) { writeln(typeid((i != 0) ? -1 : +1)); writeln(i, " ", ((i != 0) ? -1 : +1), " ", f((i != 0) ? -1 : +1)); } foreach (i; 0 .. 2) { foreach (j; 0 .. 2) { writeln(typeid((i != 0) ? -1 : +1)); writeln(i, " ", j, " ", ((i != 0) ? -1 : +1), " ", f((i != 0) ? -1 : +1)); } } } ---- (https://ideone.com/kyPT72) Its outputs are: int 0 1 1 int 1 -1 -1 int 0 0 1 1 int 0 1 1 1 int 1 0 -1 967295 int 1 1 -1 967295 printing (2^32 - 1) mod 1000000 instead of -1, only for the nested for-loop. This happens only with -m64 and -O options. --