public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/102788] New: Wrong code with -O3
@ 2021-10-15 19:54 vsevolod.livinskij at frtk dot ru
  2021-10-15 19:59 ` [Bug tree-optimization/102788] [12 Regression] " pinskia at gcc dot gnu.org
                   ` (10 more replies)
  0 siblings, 11 replies; 12+ messages in thread
From: vsevolod.livinskij at frtk dot ru @ 2021-10-15 19:54 UTC (permalink / raw)
  To: gcc-bugs

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)

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2021-11-08 12:35 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-15 19:54 [Bug tree-optimization/102788] New: Wrong code with -O3 vsevolod.livinskij at frtk dot ru
2021-10-15 19:59 ` [Bug tree-optimization/102788] [12 Regression] " pinskia at gcc dot gnu.org
2021-10-15 20:07 ` jakub at gcc dot gnu.org
2021-10-15 20:15 ` pinskia at gcc dot gnu.org
2021-10-15 20:16 ` pinskia at gcc dot gnu.org
2021-10-18  6:29 ` rguenth at gcc dot gnu.org
2021-10-18  8:38 ` rguenth at gcc dot gnu.org
2021-10-18  8:40 ` rguenth at gcc dot gnu.org
2021-10-18 10:57 ` cvs-commit at gcc dot gnu.org
2021-10-18 11:01 ` [Bug tree-optimization/102788] [11 " rguenth at gcc dot gnu.org
2021-11-08 12:35 ` rguenth at gcc dot gnu.org
2021-11-08 12:35 ` cvs-commit at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).