tree-optimization/105148 - fix IVOPTs recording uses
authorRichard Biener <rguenther@suse.de>
Tue, 5 Apr 2022 14:06:10 +0000 (16:06 +0200)
committerRichard Biener <rguenther@suse.de>
Wed, 6 Apr 2022 06:21:43 +0000 (08:21 +0200)
The following fixes recording uses in ARRAY_REFs with non-constant
element size or low bound.

2022-04-05  Richard Biener  <rguenther@suse.de>

PR tree-optimization/105148
* tree-ssa-loop-ivopts.cc (idx_record_use): Walk raw operands
2 and 3 of ARRAY_REFs.

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

gcc/testsuite/gcc.dg/torture/pr105148.c [new file with mode: 0644]
gcc/tree-ssa-loop-ivopts.cc

diff --git a/gcc/testsuite/gcc.dg/torture/pr105148.c b/gcc/testsuite/gcc.dg/torture/pr105148.c
new file mode 100644 (file)
index 0000000..3338b0f
--- /dev/null
@@ -0,0 +1,20 @@
+/* { dg-do compile } */
+
+extern void foo (void);
+
+static inline int
+bar (int n)
+{
+  for (int i = 0; i < n; i++)
+    {
+      foo ();
+      int y[1][i];
+      y[n][i] = 0;
+    }
+}
+
+int
+baz (void)
+{
+  return bar (5);
+}
index 935d2d4..581f92b 100644 (file)
@@ -2123,8 +2123,10 @@ idx_record_use (tree base, tree *idx,
   find_interesting_uses_op (data, *idx);
   if (TREE_CODE (base) == ARRAY_REF || TREE_CODE (base) == ARRAY_RANGE_REF)
     {
-      find_interesting_uses_op (data, array_ref_element_size (base));
-      find_interesting_uses_op (data, array_ref_low_bound (base));
+      if (TREE_OPERAND (base, 2))
+       find_interesting_uses_op (data, TREE_OPERAND (base, 2));
+      if (TREE_OPERAND (base, 3))
+       find_interesting_uses_op (data, TREE_OPERAND (base, 3));
     }
   return true;
 }