]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
tree-optimization/116010 - dr_may_alias regression
authorRichard Biener <rguenther@suse.de>
Fri, 24 Jan 2025 12:20:12 +0000 (13:20 +0100)
committerRichard Biener <rguenth@gcc.gnu.org>
Fri, 24 Jan 2025 13:58:48 +0000 (14:58 +0100)
r15-491-gc290e6a0b7a9de fixed a latent issue with dr_analyze_innermost
and dr_may_alias where not properly analyzed DRs would yield an invalid
answer.  This caused some missed optimizations in case there is not
actually any evolution in the not analyzed base part.  The following
recovers this by only handling base parts which reference SSA vars
as index in the conservative way.

The gfortran.dg/vect/vect-8.f90 testcase is difficult to deal with,
so the following merely bumps the maximum number of expected vectorized loops
for both aarch64 and x86-64.

PR tree-optimization/116010
* tree-data-ref.cc (contains_ssa_ref_p_1): New function.
(contains_ssa_ref_p): Likewise.
(dr_may_alias_p): Avoid treating unanalyzed base parts without
SSA reference conservatively.

* gfortran.dg/vect/vect-8.f90: Adjust.

gcc/testsuite/gfortran.dg/vect/vect-8.f90
gcc/tree-data-ref.cc

index d4ce44feb4b953e599a4df0d9128a86f756ae556..614c2a30e1b70c86cf485065f6827aaca524a267 100644 (file)
@@ -706,6 +706,6 @@ CALL track('KERNEL  ')
 RETURN
 END SUBROUTINE kernel
 
-! { dg-final { scan-tree-dump-times "vectorized 2\[56\] loops" 1 "vect" { target aarch64*-*-* } } }
-! { dg-final { scan-tree-dump-times "vectorized 2\[34567\] loops" 1 "vect" { target { vect_intdouble_cvt && { ! aarch64*-*-* } } } } }
+! { dg-final { scan-tree-dump-times "vectorized 2\[5678\] loops" 1 "vect" { target aarch64*-*-* } } }
+! { dg-final { scan-tree-dump-times "vectorized 2\[345678\] loops" 1 "vect" { target { vect_intdouble_cvt && { ! aarch64*-*-* } } } } }
 ! { dg-final { scan-tree-dump-times "vectorized 17 loops" 1 "vect" { target { { ! vect_intdouble_cvt } && { ! aarch64*-*-* } } } } }
index 08c14fe29f22950ef33f17db21b78707ecc20076..5decfb1abf5122246a9ed21aaed971b9421cf963 100644 (file)
@@ -2978,6 +2978,29 @@ object_address_invariant_in_loop_p (const class loop *loop, const_tree obj)
                                                  loop->num);
 }
 
+/* Helper for contains_ssa_ref_p.  */
+
+static bool
+contains_ssa_ref_p_1 (tree, tree *idx, void *data)
+{
+  if (TREE_CODE (*idx) == SSA_NAME)
+    {
+      *(bool *)data = true;
+      return false;
+    }
+  return true;
+}
+
+/* Returns true if the reference REF contains a SSA index. */
+
+static bool
+contains_ssa_ref_p (tree ref)
+{
+  bool res = false;
+  for_each_index (&ref, contains_ssa_ref_p_1, &res);
+  return res;
+}
+
 /* Returns false if we can prove that data references A and B do not alias,
    true otherwise.  If LOOP_NEST is false no cross-iteration aliases are
    considered.  */
@@ -3080,7 +3103,8 @@ dr_may_alias_p (const struct data_reference *a, const struct data_reference *b,
      possibly left with a non-base in which case we didn't analyze
      a possible evolution of the base when analyzing a loop.  */
   else if (loop_nest
-          && (handled_component_p (addr_a) || handled_component_p (addr_b)))
+          && ((handled_component_p (addr_a) && contains_ssa_ref_p (addr_a))
+              || (handled_component_p (addr_b) && contains_ssa_ref_p (addr_b))))
     {
       /* For true dependences we can apply TBAA.  */
       if (flag_strict_aliasing