aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTamar Christina <tamar.christina@arm.com>2024-09-30 13:06:24 +0100
committerTamar Christina <tamar.christina@arm.com>2024-09-30 13:06:24 +0100
commit87905f63a6521eef1f38082e2368e18c637ef092 (patch)
tree4546cb40085793bc85fe20b0a800fbc440532cdc
parentbac95615b50d4a012c448cba080c106702184e3a (diff)
downloadgcc-87905f63a6521eef1f38082e2368e18c637ef092.zip
gcc-87905f63a6521eef1f38082e2368e18c637ef092.tar.gz
gcc-87905f63a6521eef1f38082e2368e18c637ef092.tar.bz2
middle-end: check explicitly for external or constants when checking for loop invariant [PR116817]
The previous check if a value was external was checking !vect_get_internal_def (vinfo, var) but this of course isn't completely right as they could reductions etc. This changes the check to just explicitly look at externals and constants. Note that reductions remain unhandled here, but we don't support codegen of boolean reductions today anyway. So at the time we do then this would have the be handled as well in lowering. gcc/ChangeLog: PR tree-optimization/116817 * tree-vect-patterns.cc (vect_recog_bool_pattern): Check for const or externals. gcc/testsuite/ChangeLog: PR tree-optimization/116817 * g++.dg/vect/pr116817.cc: New test.
-rw-r--r--gcc/testsuite/g++.dg/vect/pr116817.cc16
-rw-r--r--gcc/tree-vect-patterns.cc5
2 files changed, 20 insertions, 1 deletions
diff --git a/gcc/testsuite/g++.dg/vect/pr116817.cc b/gcc/testsuite/g++.dg/vect/pr116817.cc
new file mode 100644
index 0000000..7e28982
--- /dev/null
+++ b/gcc/testsuite/g++.dg/vect/pr116817.cc
@@ -0,0 +1,16 @@
+/* { dg-do compile } */
+/* { dg-additional-options "-O3" } */
+
+int main_ulData0;
+unsigned *main_pSrcBuffer;
+int main(void) {
+ int iSrc = 0;
+ bool bData0;
+ for (; iSrc < 4; iSrc++) {
+ if (bData0)
+ main_pSrcBuffer[iSrc] = main_ulData0;
+ else
+ main_pSrcBuffer[iSrc] = 0;
+ bData0 = !bData0;
+ }
+}
diff --git a/gcc/tree-vect-patterns.cc b/gcc/tree-vect-patterns.cc
index e7e877d..b174ff1 100644
--- a/gcc/tree-vect-patterns.cc
+++ b/gcc/tree-vect-patterns.cc
@@ -6062,12 +6062,15 @@ vect_recog_bool_pattern (vec_info *vinfo,
if (get_vectype_for_scalar_type (vinfo, type) == NULL_TREE)
return NULL;
+ enum vect_def_type dt;
if (check_bool_pattern (var, vinfo, bool_stmts))
var = adjust_bool_stmts (vinfo, bool_stmts, type, stmt_vinfo);
else if (integer_type_for_mask (var, vinfo))
return NULL;
else if (TREE_CODE (TREE_TYPE (var)) == BOOLEAN_TYPE
- && !vect_get_internal_def (vinfo, var))
+ && vect_is_simple_use (var, vinfo, &dt)
+ && (dt == vect_external_def
+ || dt == vect_constant_def))
{
/* If the condition is already a boolean then manually convert it to a
mask of the given integer type but don't set a vectype. */