Ranger currently traps when it is invoked on an ssa-name which has an
SSA_NAME_DEF_STMT which does not have a BB set. This is occuring more
frequently as we extend ranger to being used for things under construction.
There is nothing fundamentally wrong with the situation, it was just
never encountered previously. This patch adjusts it such that we simply
do not go looking for range-on-entry information if the statement is not
assocaited with a block. Otherwise it will continue to try to fold the
statement and estimate a range as best it can.
Currently undergoing bootstrapping and regtests on x86_64-pc-linux-gnu.
OK if it all passes? I'm offline for a few days after today, so early
approval would be helpful :-)
Andrew
From a50f0d5b7047ce6c7ea6ed3e934c51065f34d67b Mon Sep 17 00:00:00 2001
From: Andrew MacLeod <[email protected]>
Date: Mon, 19 Jan 2026 13:44:25 -0500
Subject: [PATCH 16/16] Do not trap on a stmt with no basic block.
WHen calculating ranges for statements not in the IL, avoid looking for
range on entry values.
PR tree-optimization/123314
gcc/
* gcc/gimple-range.cc (gimple_ranger::range_on_entry): Do not check
ranger cache for an SSA_NAME with no BB.
(gimple_ranger::prefill_stmt_dependencies): Stop filling
dependencies when an out-of IL name is encountered.
gcc/testsuite/
* gcc.dg/pr123314.c: New.
---
gcc/gimple-range.cc | 5 +++--
gcc/testsuite/gcc.dg/pr123314.c | 17 +++++++++++++++++
2 files changed, 20 insertions(+), 2 deletions(-)
create mode 100644 gcc/testsuite/gcc.dg/pr123314.c
diff --git a/gcc/gimple-range.cc b/gcc/gimple-range.cc
index 491b3fb7e59..517790be216 100644
--- a/gcc/gimple-range.cc
+++ b/gcc/gimple-range.cc
@@ -171,7 +171,7 @@ gimple_ranger::range_on_entry (vrange &r, basic_block bb, tree name)
range_of_stmt (r, SSA_NAME_DEF_STMT (name), name);
// Now see if there is any on_entry value which may refine it.
- if (m_cache.block_range (entry_range, bb, name))
+ if (bb && m_cache.block_range (entry_range, bb, name))
r.intersect (entry_range);
if (idx)
@@ -389,7 +389,8 @@ gimple_ranger::prefill_stmt_dependencies (tree ssa)
unsigned idx;
gimple *stmt = SSA_NAME_DEF_STMT (ssa);
- gcc_checking_assert (stmt && gimple_bb (stmt));
+ if (!stmt || !gimple_bb (stmt))
+ return;
// Only pre-process range-ops and phis.
if (!gimple_range_op_handler::supported_p (stmt) && !is_a<gphi *> (stmt))
diff --git a/gcc/testsuite/gcc.dg/pr123314.c b/gcc/testsuite/gcc.dg/pr123314.c
new file mode 100644
index 00000000000..785992b4ff3
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr123314.c
@@ -0,0 +1,17 @@
+/* { dg-do compile } */
+/* { dg-options "-O3" } */
+/* { dg-additional-options "-march=armv9-a" { target aarch64*-*-* } } */
+/* { dg-additional-options "-march=skylake-avx512" { target x86_64*-*-* } } */
+
+extern char a[];
+extern short b[], c[];
+extern int h[];
+void i() {
+ for (char d;;)
+ for (int e = 0; e < 9; e++) {
+ for (int f; f < 9; f += 4)
+ c[d] = 0;
+ for (int g = 0; g < 9; g += 3)
+ h[1 + d] = (a[d] ? a[3] : 7 ? b[7] : 0) / 6;
+ }
+}
--
2.45.0