[Bug tree-optimization/126765] New: [15/16/17 Regression] wrong code with -O2

xxs_chy at outlook dot com via Gcc-bugs <[email protected]>
Newsgroups gmane.comp.gcc.bugs
Message-ID <[email protected]/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126765

            Bug ID: 126765
           Summary: [15/16/17 Regression] wrong code with -O2
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: xxs_chy at outlook dot com
  Target Milestone: ---

Reproducer: https://godbolt.org/z/PEj386crx
Reduced case:
#include <stdint.h>
#include <stdio.h>
#define BITCAST(DST_TYPE, SRC_TYPE, VALUE)                                    
\
    (union {                                                                  
\
        SRC_TYPE src;                                                         
\
        DST_TYPE dst                                                          
\
    }){ VALUE }                                                               
\
        .dst
typedef int8_t v2i8 __attribute__((vector_size(2)));
typedef uint8_t v2u8 __attribute__((vector_size(2)));
typedef uint64_t v16u64 __attribute__((vector_size(128)));
uint64_t __chk;
v16u64 g14 = { 5096067849,
               1020276268854195167,
               4044591831107781041,
               50030156385817,
               0,
               0,
               407226543889204245,
               3061507383067879,
               0,
               702615430303539,
               0,
               107291660716,
               4,
               7,
               50983068812403358,
               9068252662333504 };
uint16_t g23;
int main()
{
    g14 = g14 > (v16u64){};
    v2u8 bc4 = BITCAST(v2u8, uint16_t, g23 / 32879);
    bc4 = (v2i8)bc4 < (v2i8){};
    __chk = BITCAST(uint16_t, v2u8, bc4);
    printf("checksum=0x%016llx\n", (unsigned long long)__chk);
}

This case outputs checksum=0x000000000000ff00 at -O2, and outputs
checksum=0x0000000000000000 at -O0.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.