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

            Bug ID: 128630
           Summary: [14/15/16/17 Regression] wrong code at -O1:
                    VEC_PERM_EXPR fold of 256 x uchar with mask {1..255,0}
                    takes lane 255 from the second operand since r8-5628
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jeffchen006 at gmail dot com
  Target Milestone: ---

int printf(const char *, ...);
typedef unsigned char V __attribute__((vector_size(256)));
#define B(n) (n) & 255, (n + 1) & 255, (n + 2) & 255, (n + 3) & 255
#define C(n) B(n), B(n + 4), B(n + 8), B(n + 12)
#define D(n) C(n), C(n + 16), C(n + 32), C(n + 48)
int main(void) {
  V z = {}, m = { D(1), D(65), D(129), D(193) };
  V r = __builtin_shuffle(z + 7, z, m);
  printf("%d\n", r[255]);
}

$ gcc -O0 t.c && ./a.out
7
$ gcc -O1 t.c && ./a.out
0

Expected: 7. Mask element 255 is 0 (255+1 wrapped to 8 bits). Index 0 selects
lane 0 of the first operand (z + 7), so r[255] = 7. The fold extends the
stepped series to 256 and takes the lane from z.

Suspected cause: fold_vec_perm / vec_perm_indices: the wrapped 8-bit stepped
mask is extended past 255 (VECTOR_CST encoding, first bad 1a1c441dbe5, 2018).

Known to fail: 8.5.0, 10.5.0, 11.4.0, 12.5.0, 13.4.0, 14.3.0, 15.2.0, 16.2.0,
17.0.

Known to work: 7.5.0.

-O0 -fsanitize=undefined,address is clean.

gcc version 17.0.0 20261111 (experimental) (a2a11abfad3), x86_64-pc-linux-gnu
Configured with: --enable-languages=c,c++ --disable-multilib
--disable-bootstrap --enable-checking=release

Related: PR128080, PR128451.
  • [Bug middle-end/128630] New: [14... jeffchen006 at gmail dot com via Gcc-bugs

Reply via email to