https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114090
Bug ID: 114090 Summary: forwprop -fwrapv miscompilation Product: gcc Version: 14.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: kristerw at gcc dot gnu.org Target Milestone: --- The function f below returns an incorrect result for INT_MIN when compiled with -O1 -fwrapv for X86_64: __attribute__((noipa)) int f(int x) { int w = (x >= 0 ? x : 0); int y = -x; int z = (y >= 0 ? y : 0); return w + z; } int main () { if (f(0x80000000) != 0) __builtin_abort (); return 0; } What is happening is that forwprop has optimized w_2 = MAX_EXPR <x_1(D), 0>; y_3 = -x_1(D); z_4 = MAX_EXPR <y_3, 0>; _5 = w_2 + z_4; return _5; to _5 = ABS_EXPR <x_1(D)>; return _5;