[COMMITTED] PR tree-optimization/162538 - Limit the number of iterations in phi analyzer.
Andrew MacLeod <[email protected]>
| Newsgroups | gmane.comp.gcc.patches |
|---|---|
| Message-ID | <[email protected]> |
The phi analyzer limits the number of iterations it simulates a modifier statement by the precision of the type. This is so we can capture small values and shifts that converge. As the PR shows, BitInt (65535) makes this a rather inappropriate thing to do. Jakub suggested using MAX_FIXED_MODE_SIZE as an upper bound on this, and this patch implements that. Bootstrapped on x86_64-pc-linux-gnu with no regressions. pushed. Andrew
0001-Limit-the-number-of-iterations-in-phi-analyzer.patch
(text/x-patch, 1.8 KB)
From 92314bcdddf7bfa8c9e54029b4765bc2ce41a39a Mon Sep 17 00:00:00 2001 From: Andrew MacLeod <[email protected]> Date: Wed, 12 Aug 2026 14:34:00 -0400 Subject: [PATCH 1/4] Limit the number of iterations in phi analyzer. The phi analyzer attempts to provide initial values for cyclic PHIs by simulating the modifer by the number of bits of precision. _BitInt objects can be very large, and it is pointless to try to simulate them that many ttimes. PR tree-optimization/126538 gcc/ * gimple-range-phi.cc (phi_group::calculate_using_modifier): Limit the iteration upper bound to MAX_FIXED_MODE_SIZE. gcc/testsuite/ * gcc.dg/pr126538.c: New. --- gcc/gimple-range-phi.cc | 2 +- gcc/testsuite/gcc.dg/pr126538.c | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.dg/pr126538.c diff --git a/gcc/gimple-range-phi.cc b/gcc/gimple-range-phi.cc index 82dd86a095a..f680e87c7ee 100644 --- a/gcc/gimple-range-phi.cc +++ b/gcc/gimple-range-phi.cc @@ -164,7 +164,7 @@ phi_group::calculate_using_modifier (range_query *q) // Limit iterations to 1 more than the number of bits. unsigned num_iter; if (do_iterative) - num_iter = TYPE_PRECISION (m_vr.type ()) + 1; + num_iter = MIN (TYPE_PRECISION (m_vr.type ()), MAX_FIXED_MODE_SIZE) + 1; else num_iter = 0; diff --git a/gcc/testsuite/gcc.dg/pr126538.c b/gcc/testsuite/gcc.dg/pr126538.c new file mode 100644 index 00000000000..7aae1d728e8 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr126538.c @@ -0,0 +1,19 @@ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ + +typedef _BitInt(65535) T; + +__attribute__((noipa)) T +f (int n) +{ + T x = 1; + for (int i = 0; i < n; i++) + x = x * 3; + return x; +} + +int +main (void) +{ + return (int) f (2) - 9; +} -- 2.45.0