[Bug tree-optimization/102788] New: Wrong code with -O3

vsevolod.livinskij at frtk dot ru gcc-bugzilla@gcc.gnu.org
Fri Oct 15 19:54:21 GMT 2021


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102788

            Bug ID: 102788
           Summary: Wrong code with -O3
           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/78ab77Env

Reproducer:
#include <stdio.h>

unsigned long long int var_4 = 235;
unsigned long long int var_5 = 74;
signed char var_12 = -99;
unsigned long long int var_349;
unsigned char var_645;
void test();

const unsigned long long &min(const unsigned long long &a, const unsigned long
long &b) {
  return b < a ? b : a;
}

void test() __attribute__((noipa));
void test() {
    for (short c = var_12; c; c += 5)
      ; 
    for (int e = 0; e < 12; e += 1) {
      var_349 = var_4 ? 235 : 74;
      var_645 = min((unsigned long long)true, var_5 ? var_12 : var_4);
    }
}

int main() {
    test();
    printf("%d\n", (int)var_645);
    //if (var_645 != 1)
    //  __builtin_abort();
}

Error:
>$g++ -O2 small.cpp && ./a.out 
1
>$g++ -O3 small.cpp && ./a.out 
255

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 20211011 (30cce6f65a77b8eaa22f3efff7f1ba54858106f9) (GCC)


More information about the Gcc-bugs mailing list