The SLP graph representation made vect_attempt_slp_rearrange_stmts unsafe since
it fails to verify the permutation it applies only affects the SLP reduction.
foo (unsigned *q, unsigned *r)
unsigned sum1 = 0, sum2 = 0;
for (int i = 0; i < 512; ++i)
sum1 += a[2*i];
sum2 += a[2*i+1];
b[2*i] = a[2*i+1];
b[2*i+1] = a[2*i];
*q = sum1;
*r = sum2;
unsigned sum1, sum2;
a = 0;
a = 1;
foo (&sum1, &sum2);
if (b != 1 || b != 0)
Just for the record, started with r10-4800-g10a73df76280e128.
What's more we cannot modify the SLP nodes stmt order since they are cached in
the SLP node cache. So a "simple" fix might be to COW the whole SLP sub-tree
The master branch has been updated by Richard Guenther <email@example.com>:
Author: Richard Biener <firstname.lastname@example.org>
Date: Tue Feb 25 10:31:16 2020 +0100
tree-optimization/93868 copy SLP tree before re-arranging stmts
This avoids altering possibly shared SLP subtrees when attempting
to get rid of permutations in SLP reductions by copying the SLP
subtree before re-arranging stmts in it.
2020-02-25 Richard Biener <email@example.com>
* tree-vect-slp.c (slp_copy_subtree): New function.
(vect_attempt_slp_rearrange_stmts): Copy the SLP tree before
re-arranging stmts in it.
* gcc.dg/torture/pr93868.c: New testcase.