https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78726
Bug ID: 78726 Summary: [5/6/7 Regression] Incorrect unsigned arithmetic optimization Product: gcc Version: 7.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: middle-end Assignee: unassigned at gcc dot gnu.org Reporter: babokin at gmail dot com Target Milestone: --- Created attachment 40279 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=40279&action=edit reproducer -O2 produces different result than -O0 for unsigned arithmetic. Reproduces with gcc 5, 6, and 7, while 4.9 works fine. > cat driver.cpp #include <stdio.h> unsigned char A = 36; unsigned char B = 173; unsigned long int C; extern void foo (); int main () { foo (); printf("%lu\n", C); return 0; } > cat func.cpp extern unsigned char A; extern unsigned char B; extern unsigned long int C; void foo() { unsigned a = ~A; C = a * B * B + 1023094746 * a; } > g++ -O0 -o no_opt driver.cpp func.cpp > ./no_opt 799092689 > g++ -O2 -o opt driver.cpp func.cpp > ./opt 800200062