https://gcc.gnu.org/g:02fc12b04017d20345e208d65fd7a33d62f0cded

commit r15-7177-g02fc12b04017d20345e208d65fd7a33d62f0cded
Author: Richard Biener <rguent...@suse.de>
Date:   Fri Jan 24 13:20:12 2025 +0100

    tree-optimization/116010 - dr_may_alias regression
    
    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.

Diff:
---
 gcc/testsuite/gfortran.dg/vect/vect-8.f90 |  4 ++--
 gcc/tree-data-ref.cc                      | 26 +++++++++++++++++++++++++-
 2 files changed, 27 insertions(+), 3 deletions(-)

diff --git a/gcc/testsuite/gfortran.dg/vect/vect-8.f90 
b/gcc/testsuite/gfortran.dg/vect/vect-8.f90
index d4ce44feb4b9..614c2a30e1b7 100644
--- a/gcc/testsuite/gfortran.dg/vect/vect-8.f90
+++ b/gcc/testsuite/gfortran.dg/vect/vect-8.f90
@@ -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*-*-* } } } } }
diff --git a/gcc/tree-data-ref.cc b/gcc/tree-data-ref.cc
index 08c14fe29f22..5decfb1abf51 100644
--- a/gcc/tree-data-ref.cc
+++ b/gcc/tree-data-ref.cc
@@ -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

Reply via email to