tree-optimization/105148 - fix IVOPTs recording uses
Commit Message
The following fixes recording uses in ARRAY_REFs with non-constant
element size or low bound.
Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed.
Richard.
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 | 20 ++++++++++++++++++++
gcc/tree-ssa-loop-ivopts.cc | 6 ++++--
2 files changed, 24 insertions(+), 2 deletions(-)
create mode 100644 gcc/testsuite/gcc.dg/torture/pr105148.c
new file mode 100644
@@ -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);
+}
@@ -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;
}