From: Richard Biener Date: Tue, 5 Apr 2022 14:06:10 +0000 (+0200) Subject: tree-optimization/105148 - fix IVOPTs recording uses X-Git-Tag: basepoints/gcc-13~299 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=86242eb1bd03eba82d8e22b01b16925d43bcc539;p=thirdparty%2Fgcc.git tree-optimization/105148 - fix IVOPTs recording uses The following fixes recording uses in ARRAY_REFs with non-constant element size or low bound. 2022-04-05 Richard Biener 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. --- diff --git a/gcc/testsuite/gcc.dg/torture/pr105148.c b/gcc/testsuite/gcc.dg/torture/pr105148.c new file mode 100644 index 000000000000..3338b0f3281b --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr105148.c @@ -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); +} diff --git a/gcc/tree-ssa-loop-ivopts.cc b/gcc/tree-ssa-loop-ivopts.cc index 935d2d4d8f33..581f92b059bb 100644 --- a/gcc/tree-ssa-loop-ivopts.cc +++ b/gcc/tree-ssa-loop-ivopts.cc @@ -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; }