]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ipa/111036 - strip nop conversions around __builtin_constant_p arguments
authorRichard Biener <rguenther@suse.de>
Wed, 28 Jan 2026 09:55:56 +0000 (10:55 +0100)
committerRichard Biener <rguenth@gcc.gnu.org>
Wed, 28 Jan 2026 11:52:30 +0000 (12:52 +0100)
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.

gcc/match.pd
gcc/testsuite/gcc.dg/torture/pr111036.c [new file with mode: 0644]

index 01b95ec075538fcd36d1a2dcc8abfa728e2c582d..d86429f5dd8f1908dc5d1e96b8dbd4913a0bde67 100644 (file)
@@ -12236,3 +12236,8 @@ and,
    long as the requested element is within range.  */
 (simplify (IFN_VEC_EXTRACT (vec_duplicate @0) INTEGER_CST@1)
  @0)
+
+/* 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 (file)
index 0000000..f3a0e61
--- /dev/null
@@ -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;
+}
+