From 87905f63a6521eef1f38082e2368e18c637ef092 Mon Sep 17 00:00:00 2001 From: Tamar Christina Date: Mon, 30 Sep 2024 13:06:24 +0100 Subject: 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. --- gcc/tree-vect-patterns.cc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'gcc/tree-vect-patterns.cc') 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. */ -- cgit v1.1