diff options
author | Richard Biener <rguenther@suse.de> | 2025-09-03 10:04:58 +0200 |
---|---|---|
committer | Richard Biener <rguenth@gcc.gnu.org> | 2025-09-03 13:02:35 +0200 |
commit | 41e2fe9be1ff5ef2eafd49b30882898d26b9bf36 (patch) | |
tree | 16683c6ea13ad1dfa7982c5f089b52c2d735c32c /gcc | |
parent | b905810be2ebd271d759d66cc2588e7b8180cc39 (diff) | |
download | gcc-41e2fe9be1ff5ef2eafd49b30882898d26b9bf36.zip gcc-41e2fe9be1ff5ef2eafd49b30882898d26b9bf36.tar.gz gcc-41e2fe9be1ff5ef2eafd49b30882898d26b9bf36.tar.bz2 |
tree-optimization/121758 - fix pattern stmt REDUC_IDX updating
The following fixes a corner case of pattern stmt STMT_VINFO_REDUC_IDX
updating which happens auto-magically. When a 2nd pattern sequence
uses defs from inside a prior pattern sequence then the first guess
for the lookfor can be off. This happens when for example widening
patterns use vect_get_internal_def, which looks into earlier patterns.
PR tree-optimization/121758
* tree-vect-patterns.cc (vect_mark_pattern_stmts): Try
harder to find a reduction continuation.
* gcc.dg/vect/pr121758.c: New testcase.
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/testsuite/gcc.dg/vect/pr121758.c | 15 | ||||
-rw-r--r-- | gcc/tree-vect-patterns.cc | 30 |
2 files changed, 39 insertions, 6 deletions
diff --git a/gcc/testsuite/gcc.dg/vect/pr121758.c b/gcc/testsuite/gcc.dg/vect/pr121758.c new file mode 100644 index 0000000..b27bc67 --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/pr121758.c @@ -0,0 +1,15 @@ +/* { dg-do compile } */ + +long g_2205, g_3005; +int g_3320; +void main() +{ + for (; g_2205; g_2205 += 1) + { + g_3005 = 0; + for (; g_3005 <= 8; g_3005 += 1) + g_3320 &= 611 & (unsigned char)g_3005; + } +} + +/* { dg-final { scan-tree-dump-not "failed to update reduction index" "vect" } } */ diff --git a/gcc/tree-vect-patterns.cc b/gcc/tree-vect-patterns.cc index d0bf2f9..41ca0f0 100644 --- a/gcc/tree-vect-patterns.cc +++ b/gcc/tree-vect-patterns.cc @@ -7074,14 +7074,32 @@ vect_mark_pattern_stmts (vec_info *vinfo, { bool found = false; if (gimple_extract_op (s, &op)) - for (unsigned i = 0; i < op.num_ops; ++i) - if (op.ops[i] == lookfor) + { + for (unsigned i = 0; i < op.num_ops; ++i) + if (op.ops[i] == lookfor) + { + STMT_VINFO_REDUC_IDX (vinfo->lookup_stmt (s)) = i; + lookfor = gimple_get_lhs (s); + found = true; + break; + } + /* Try harder to find a mid-entry into an earlier pattern + sequence. This means that the initial 'lookfor' was + bogus. */ + if (!found) { - STMT_VINFO_REDUC_IDX (vinfo->lookup_stmt (s)) = i; - lookfor = gimple_get_lhs (s); - found = true; - break; + for (unsigned i = 0; i < op.num_ops; ++i) + if (TREE_CODE (op.ops[i]) == SSA_NAME) + if (auto def = vinfo->lookup_def (op.ops[i])) + if (vect_is_reduction (def)) + { + STMT_VINFO_REDUC_IDX (vinfo->lookup_stmt (s)) = i; + lookfor = gimple_get_lhs (s); + found = true; + break; + } } + } if (s == pattern_stmt) { if (!found && dump_enabled_p ()) |