https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105142
Bug ID: 105142 Summary: [12 Regression] Wrong code with -O2 Product: gcc Version: 12.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: vsevolod.livinskiy at gmail dot com Target Milestone: --- Link to the Compiler Explorer: https://godbolt.org/z/51v98a6fd Reproducer: #include <stdio.h> long long int arr_248 = 3623214276426624192LL; unsigned short arr_255; void test() __attribute__((noipa)); char a = 42; const long long &min(const long long &c, const long long &d) { return c < d ? c : d; } void test() { arr_255 = min(a, min(a, arr_248) + 5713568809962283044LL); } int main() { test(); printf("%u\n", arr_255); if (arr_255 != 42) __builtin_abort(); } Error: >$ g++ -O1 small.cpp && ./a.out 42 >$ g++ -O2 small.cpp && ./a.out 3300 Aborted (core dumped) gcc version 12.0.1 20220401 (git://gcc.gnu.org/git/gcc.git:master 15d683d4f0b390b27c54a7c92c6e4f33195bdc93)