]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
tree-optimization/116768 - wrong dependence analysis
authorRichard Biener <rguenther@suse.de>
Thu, 19 Sep 2024 12:58:18 +0000 (14:58 +0200)
committerRichard Biener <rguenth@gcc.gnu.org>
Fri, 17 Jan 2025 08:52:40 +0000 (09:52 +0100)
The following reverts a bogus fix done for PR101009 and instead makes
sure we get into the same_access_functions () case when computing
the distance vector for g[1] and g[1] where the constants ended up
having different types.  The generic code doesn't seem to handle
loop invariant dependences.  The special case gets us both
( 0 ) and ( 1 ) as distance vectors while formerly we got ( 1 ),
which the PR101009 fix changed to ( 0 ) with bad effects on other
cases as shown in this PR.

PR tree-optimization/116768
* tree-data-ref.cc (build_classic_dist_vector_1): Revert
PR101009 change.
* tree-chrec.cc (eq_evolutions_p): Make sure (sizetype)1
and (int)1 compare equal.

* gcc.dg/torture/pr116768.c: New testcase.

(cherry picked from commit 5b5a36b122e1205449f1512bf39521b669e713ef)

gcc/testsuite/gcc.dg/torture/pr116768.c [new file with mode: 0644]
gcc/tree-chrec.cc
gcc/tree-data-ref.cc

diff --git a/gcc/testsuite/gcc.dg/torture/pr116768.c b/gcc/testsuite/gcc.dg/torture/pr116768.c
new file mode 100644 (file)
index 0000000..57b5d00
--- /dev/null
@@ -0,0 +1,32 @@
+/* { dg-do run } */
+
+#define numwords 2
+
+typedef struct {
+  unsigned words[numwords];
+} Child;
+
+typedef struct {
+  Child child;
+} Parent;
+
+Parent my_or(Parent x, const Parent *y) {
+  const Child *y_child = &y->child;
+  for (int i = 0; i < numwords; i++) {
+    x.child.words[i] |= y_child->words[i];
+  }
+  return x;
+}
+
+int main() {
+  Parent bs[4];
+  __builtin_memset(bs, 0, sizeof(bs));
+
+  bs[0].child.words[0] = 1;
+  for (int i = 1; i <= 3; i++) {
+    bs[i] = my_or(bs[i], &bs[i - 1]);
+  }
+  if (bs[2].child.words[0] != 1)
+    __builtin_abort ();
+  return 0;
+}
index c44cea7543441ee0a4977beeb8d8d6e6554bee60..685e975cf2bc5498292f5d81c068191ea8a05b99 100644 (file)
@@ -1594,7 +1594,7 @@ eq_evolutions_p (const_tree chrec0, const_tree chrec1)
       || TREE_CODE (chrec0) != TREE_CODE (chrec1))
     return false;
 
-  if (chrec0 == chrec1)
+  if (operand_equal_p (chrec0, chrec1, 0))
     return true;
 
   if (! types_compatible_p (TREE_TYPE (chrec0), TREE_TYPE (chrec1)))
@@ -1621,7 +1621,7 @@ eq_evolutions_p (const_tree chrec0, const_tree chrec1)
                              TREE_OPERAND (chrec1, 0));
 
     default:
-      return operand_equal_p (chrec0, chrec1, 0);
+      return false;
     }
 }
 
index b7bca6a9d06412504c709f53e44c85e5cbb4f736..ea55f81a92fc78cd2f9505b693c45667ed134cb6 100644 (file)
@@ -5168,8 +5168,6 @@ build_classic_dist_vector_1 (struct data_dependence_relation *ddr,
          non_affine_dependence_relation (ddr);
          return false;
        }
-      else
-       *init_b = true;
     }
 
   return true;