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?
Andrew
From 8aeb27ad66ba2a7fd86155d541293c62fd0f0763 Mon Sep 17 00:00:00 2001
From: Andrew MacLeod <[email protected]>
Date: Mon, 15 Dec 2025 16:26:19 -0500
Subject: [PATCH 07/16] 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, special casing -1.
---
gcc/gimple-fold.cc | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/gcc/gimple-fold.cc b/gcc/gimple-fold.cc
index e9019e2c7bd..e92dae26dce 100644
--- a/gcc/gimple-fold.cc
+++ b/gcc/gimple-fold.cc
@@ -2012,6 +2012,16 @@ 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
+ && tree_int_cst_sgn (arg) >= 0)
+ {
+ if (!integer_all_onesp (arg))
+ return arg;
+ return NULL_TREE;
+ }
+
/* 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