From: Tamar Christina Date: Mon, 30 Sep 2024 12:06:24 +0000 (+0100) Subject: middle-end: check explicitly for external or constants when checking for loop invaria... X-Git-Tag: basepoints/gcc-16~5594 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=87905f63a6521eef1f38082e2368e18c637ef092;p=thirdparty%2Fgcc.git 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. --- diff --git a/gcc/testsuite/g++.dg/vect/pr116817.cc b/gcc/testsuite/g++.dg/vect/pr116817.cc new file mode 100644 index 00000000000..7e28982fb13 --- /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 e7e877dd2ad..b174ff1e705 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. */