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. unsigned a[1024]; unsigned b[1024]; void __attribute__((noipa)) 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; } int main() { unsigned sum1, sum2; a[0] = 0; a[1] = 1; foo (&sum1, &sum2); if (b[0] != 1 || b[1] != 0) __builtin_abort (); return 0; }
Mine.
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 we re-arrange...
The master branch has been updated by Richard Guenther <rguenth@gcc.gnu.org>: https://gcc.gnu.org/g:81c833b311b16cfd87a947374d5ffbbd48facd03 commit r10-6838-g81c833b311b16cfd87a947374d5ffbbd48facd03 Author: Richard Biener <rguenther@suse.de> 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 <rguenther@suse.de> PR tree-optimization/93868 * 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.
Fixed.