[gcc r17-3296] Limit the number of iterations in phi analyzer.
Andrew Macleod via Gcc-cvs <[email protected]>
| Newsgroups | gmane.comp.gcc.cvs |
|---|---|
| Message-ID | <[email protected]> |
https://gcc.gnu.org/g:21c8ddd2cd2f3bf64225e4523e20e795083676fb commit r17-3296-g21c8ddd2cd2f3bf64225e4523e20e795083676fb Author: Andrew MacLeod <[email protected]> Date: Wed Aug 12 14:34:00 2026 -0400 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. Diff: --- gcc/gimple-range-phi.cc | 2 +- gcc/testsuite/gcc.dg/pr126538.c | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/gcc/gimple-range-phi.cc b/gcc/gimple-range-phi.cc index 82dd86a095a4..f680e87c7ee0 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 000000000000..7aae1d728e84 --- /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; +}