On 5/5/26 02:20, Richard Biener wrote:
On Mon, May 4, 2026 at 7:24 PM Andrew MacLeod <[email protected]> wrote:
get_maxval_strlen () in gimple-fold.cc creates a bitmap for
get_range_strlen to use.  If an integer constant is passed in, it
creates a a lot of overhead for no real reason.

I also have upcoming uses of it which, although I don't have it in front
of me, also wasn't working properly for the constant path.

This patch simply checks for the constant condition up front, and
returns the value which would have been returned had the
get_range_strlen been called. I note that +INF is a special case and is
suppose to return NULL_TREE, which is what this patch also does.

Bootstrapped on x86_64-pc-linux-gnu with no regressions. Is this OK for
trunk?
I believe for SRK_INT_VALUE, aka "Determine the integer value of the
argument (not string length)."
you can simply return arg if INTEGER_CST, without checking it's sign
or against maxval.

OK with that change.

Huh, interesting.  Back in january I had a couple of testsuite failures when I tried that.. but they seem to be gone... perhaps it was something transient...

anyway, this is what I checked in.  Bootstraps on x86_64-pc-linux-gnu with no regressions.  Pushed.

Andrew
From 6712abb759a0be27cbf3019bf77a313c5bb86796 Mon Sep 17 00:00:00 2001
From: Andrew MacLeod <[email protected]>
Date: Mon, 15 Dec 2025 16:26:19 -0500
Subject: [PATCH 1/2] Handle integer constants up front.

If passed an integer constant, return that constant.

	* gimple-fold.cc (get_maxval_strlen): Return the same value if
	passed a constant.
---
 gcc/gimple-fold.cc | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/gcc/gimple-fold.cc b/gcc/gimple-fold.cc
index 4ec6cc65e3a..65239044255 100644
--- a/gcc/gimple-fold.cc
+++ b/gcc/gimple-fold.cc
@@ -2012,6 +2012,11 @@ get_maxval_strlen (tree arg, strlen_range_kind rkind, tree *nonstr = NULL)
   /* A non-null NONSTR is meaningless when determining the maximum
      value of an integer ARG.  */
   gcc_assert (rkind != SRK_INT_VALUE || nonstr == NULL);
+
+  // If arg is already a constant, simply return it.
+  if (TREE_CODE (arg) == INTEGER_CST && rkind == SRK_INT_VALUE)
+    return arg;
+
   /* ARG must have an integral type when RKIND says so.  */
   gcc_assert (rkind != SRK_INT_VALUE || INTEGRAL_TYPE_P (TREE_TYPE (arg)));
 
-- 
2.45.0

Reply via email to