Late FRE uncovered a bug in vec-perm folding.
Boostrap / regtest running on x86_64-unknown-linux-gnu. Richard. 2019-07-03 Richard Biener <rguent...@suse.de> PR middle-end/91069 * match.pd (vec_perm -> bit_insert): Fix element read from first vector. * gcc.dg/pr91069.c: New testcase. Index: gcc/match.pd =================================================================== --- gcc/match.pd (revision 272958) +++ gcc/match.pd (working copy) @@ -5520,7 +5520,7 @@ (define_operator_list COND_TERNARY first vector we only can insert the first elt from the first vector. */ at = 0; - if ((ins = fold_read_from_vector (cop0, 0))) + if ((ins = fold_read_from_vector (cop0, sel[0]))) op0 = op1; } else Index: gcc/testsuite/gcc.dg/pr91069.c =================================================================== --- gcc/testsuite/gcc.dg/pr91069.c (nonexistent) +++ gcc/testsuite/gcc.dg/pr91069.c (working copy) @@ -0,0 +1,19 @@ +/* { dg-do run } */ + +typedef double v2df __attribute__((vector_size(16))); +typedef long v2di __attribute__((vector_size(16))); + +void foo (v2df *res, v2df *src) +{ + v2df x = *src; + *res = __builtin_shuffle ((v2df) { 1.0, 0.0 }, x, (v2di) { 1, 3 }); +} + +int main() +{ + v2df x = (v2df) { 0.0, 2.0 }; + foo (&x, &x); + if (x[0] != 0.0 || x[1] != 2.0) + __builtin_abort (); + return 0; +}