https://gcc.gnu.org/g:19a2172b22961d74074fb602e9b82d44ef6e1fc7
commit r17-6291-g19a2172b22961d74074fb602e9b82d44ef6e1fc7 Author: Jiawei <[email protected]> Date: Sun Nov 15 15:34:54 2026 +0800 tree-optimization: Fix LIM dependence cache indexing Parenthesize the dependence-state comparison so the cache index includes the loop number and dependence kind. This allows cached dependence results to be reused. Tested on x86_64-pc-linux-gnu with C selftests and tree-ssa.exp=ssa-lim-*.c (61 PASS). The new test fails before the fix and passes afterwards. gcc/ChangeLog: * tree-ssa-loop-im.cc (record_loop_dependence): Parenthesize the dependence-state comparison. gcc/testsuite/ChangeLog: * gcc.dg/tree-ssa/ssa-lim-27.c: New test. Diff: --- gcc/testsuite/gcc.dg/tree-ssa/ssa-lim-27.c | 18 ++++++++++++++++++ gcc/tree-ssa-loop-im.cc | 2 +- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/gcc/testsuite/gcc.dg/tree-ssa/ssa-lim-27.c b/gcc/testsuite/gcc.dg/tree-ssa/ssa-lim-27.c new file mode 100644 index 000000000000..7eb2e2adc5c7 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/ssa-lim-27.c @@ -0,0 +1,18 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-lim2-details" } */ + +void +foo (int *p, int *q, int n, int m) +{ + for (int i = 0; i < n; ++i) + { + int j = 0; + do + p[j] = *q + i; + while (++j < m); + } +} + +/* Reuse the cached result for the inner loop. Each loop should require + only one RAW dependence query. */ +/* { dg-final { scan-tree-dump-times "Querying RAW dependencies" 2 "lim2" } } */ diff --git a/gcc/tree-ssa-loop-im.cc b/gcc/tree-ssa-loop-im.cc index 5bbeb5048b23..4577887c53ad 100644 --- a/gcc/tree-ssa-loop-im.cc +++ b/gcc/tree-ssa-loop-im.cc @@ -162,7 +162,7 @@ record_loop_dependence (class loop *loop, im_mem_ref *ref, dep_kind kind, dep_state state) { gcc_assert (state != dep_unknown); - unsigned bit = 6 * loop->num + kind * 2 + state == dep_dependent ? 1 : 0; + unsigned bit = 6 * loop->num + kind * 2 + (state == dep_dependent); bitmap_set_bit (&ref->dep_loop, bit); }
