[gcc r13-10145] ipa/111036 - strip nop conversions around __builtin_constant_p arguments
Richard Biener
rguenth@gcc.gnu.org
Fri Mar 20 09:59:11 GMT 2026
https://gcc.gnu.org/g:453b952a787d28e9a3081f0b0786cd3ed7ffa7b9
commit r13-10145-g453b952a787d28e9a3081f0b0786cd3ed7ffa7b9
Author: Richard Biener <rguenther@suse.de>
Date: Wed Jan 28 10:55:56 2026 +0100
ipa/111036 - strip nop conversions around __builtin_constant_p arguments
The PR is about inconsistent behavior wrt inline predicate analysis
and later folding of __builtin_constant_p which ultimatively results
from fold_builtin_constant_p stripping nops off its argument but
this not being done on GIMPLE. The following adds a match.pd pattern
for this.
PR ipa/111036
* match.pd (__builtin_constant_p ((T)x)): Strip nop-conversions
from __builtin_constant_p arguments.
* gcc.dg/torture/pr111036.c: New testcase.
(cherry picked from commit 8c0458505a9b1b276fbad81d20849b88eda12d24)
Diff:
---
gcc/match.pd | 5 +++++
gcc/testsuite/gcc.dg/torture/pr111036.c | 24 ++++++++++++++++++++++++
2 files changed, 29 insertions(+)
diff --git a/gcc/match.pd b/gcc/match.pd
index bbcc6587569d..b3c755e75bc8 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -8528,3 +8528,8 @@ and,
}
(if (full_perm_p)
(vec_perm (op@3 @0 @1) @3 @2))))))
+
+/* Strip nop-conversions __builtin_constant_p arguments. */
+(simplify
+ (BUILT_IN_CONSTANT_P (nop_convert@1 @0))
+ (BUILT_IN_CONSTANT_P @0))
diff --git a/gcc/testsuite/gcc.dg/torture/pr111036.c b/gcc/testsuite/gcc.dg/torture/pr111036.c
new file mode 100644
index 000000000000..f3a0e61705d2
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr111036.c
@@ -0,0 +1,24 @@
+/* { dg-do run } */
+
+#include <stdlib.h>
+
+__attribute__((aligned(32))) static struct
+{
+ unsigned long long available_cmd_ids_per_core[2];
+} _rl2c_cmd_id_data;
+
+static inline void __attribute__((always_inline))
+foo (void *base, size_t length)
+{
+ unsigned long int p = (unsigned long int) base;
+ if (__builtin_constant_p(p) && (p & 31) == 0) { exit (0); }
+ else if (__builtin_constant_p(length)) { exit (0); }
+ else { exit (0); }
+}
+
+int main(int argc, char **argv)
+{
+ foo(&_rl2c_cmd_id_data, sizeof(*(&_rl2c_cmd_id_data)));
+ return 0;
+}
+
More information about the Gcc-cvs
mailing list