https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103037
Bug ID: 103037 Summary: [11/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.livinskij at frtk dot ru Target Milestone: --- Link to the Compiler Explorer: https://godbolt.org/z/eaGzsPnax Reproducer: #include <stdio.h> short var_3 = 2; unsigned char var_9 = 23; unsigned short var_11; unsigned short arr_4 [23]; void test() __attribute__((noipa)); const unsigned short &min(unsigned short &d, const unsigned short &e) { return e < d ? e : d; } void test() { for (int a = 0; a < var_9; a += 3) var_11 = min(arr_4[a], 1) / (arr_4[a] ? arr_4[a] : var_3); } int main() { for (size_t i_0 = 0; i_0 < 23; ++i_0) arr_4 [i_0] = 2; test(); printf("%hu\n", var_11); if (var_11 != 0) __builtin_abort(); } Error: >$ g++ driver.cpp -O0 && ./a.out 0 >$ g++ driver.cpp -O2 && ./a.out 1 GCC version: Using built-in specs. COLLECT_GCC=g++ COLLECT_LTO_WRAPPER=/testing/gcc/bin_master/libexec/gcc/x86_64-pc-linux-gnu/12.0.0/lto-wrapper Target: x86_64-pc-linux-gnu Configured with: /testing/gcc/gcc_src_master/configure --enable-multilib --prefix=/testing/gcc/bin_master --disable-bootstrap Thread model: posix Supported LTO compression algorithms: zlib gcc version 12.0.0 20211101 (679652a77da60078392a834ed4b6b910127dbf24) (GCC)