diff options
author | Richard Biener <rguenther@suse.de> | 2024-02-22 10:50:12 +0100 |
---|---|---|
committer | Richard Biener <rguenther@suse.de> | 2024-06-21 11:20:51 +0200 |
commit | b6a029286d5034d63063ae78f406ba677c37d015 (patch) | |
tree | edead8449a3676c4a35df4359ed29e0ed934ddfc | |
parent | a43c9bea7bd80af33ae116e7197f814ad911857e (diff) | |
download | gcc-b6a029286d5034d63063ae78f406ba677c37d015.zip gcc-b6a029286d5034d63063ae78f406ba677c37d015.tar.gz gcc-b6a029286d5034d63063ae78f406ba677c37d015.tar.bz2 |
tree-optimization/114027 - conditional reduction chain
When we classify a conditional reduction chain as CONST_COND_REDUCTION
we fail to verify all involved conditionals have the same constant.
That's a quite unlikely situation so the following simply disables
such classification when there's more than one reduction statement.
PR tree-optimization/114027
* tree-vect-loop.c (vecctorizable_reduction): Use optimized
condition reduction classification only for single-element
chains.
* gcc.dg/vect/pr114027.c: New testcase.
(cherry picked from commit 549f251f055e3a0b0084189a3012c4f15d635e75)
-rw-r--r-- | gcc/testsuite/gcc.dg/vect/pr114027.c | 26 | ||||
-rw-r--r-- | gcc/tree-vect-loop.c | 11 |
2 files changed, 32 insertions, 5 deletions
diff --git a/gcc/testsuite/gcc.dg/vect/pr114027.c b/gcc/testsuite/gcc.dg/vect/pr114027.c new file mode 100644 index 0000000..ead9cdd --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/pr114027.c @@ -0,0 +1,26 @@ +#include "tree-vect.h" + +int __attribute__((noipa)) +foo (int *f, int n) +{ + int res = 0; + for (int i = 0; i < n; ++i) + { + if (f[2*i]) + res = 2; + if (f[2*i+1]) + res = -2; + } + return res; +} + +int f[] = { 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 0 }; + +int +main () +{ + if (foo (f, 16) != 2) + __builtin_abort (); + return 0; +} diff --git a/gcc/tree-vect-loop.c b/gcc/tree-vect-loop.c index 01d1361..48dbdc2 100644 --- a/gcc/tree-vect-loop.c +++ b/gcc/tree-vect-loop.c @@ -6762,17 +6762,18 @@ vectorizable_reduction (loop_vec_info loop_vinfo, < GET_MODE_SIZE (SCALAR_TYPE_MODE (TREE_TYPE (vectype_op[i])))))) vectype_in = vectype_op[i]; - if (code == COND_EXPR) + /* Record how the non-reduction-def value of COND_EXPR is defined. + ??? For a chain of multiple CONDs we'd have to match them up all. */ + if (code == COND_EXPR && reduc_chain_length == 1) { - /* Record how the non-reduction-def value of COND_EXPR is defined. */ if (dt == vect_constant_def) { cond_reduc_dt = dt; cond_reduc_val = op; } - if (dt == vect_induction_def - && def_stmt_info - && is_nonwrapping_integer_induction (def_stmt_info, loop)) + else if (dt == vect_induction_def + && def_stmt_info + && is_nonwrapping_integer_induction (def_stmt_info, loop)) { cond_reduc_dt = dt; cond_stmt_vinfo = def_stmt_info; |