https://gcc.gnu.org/g:9f7a095e81bd3bafbc0fd66ab210a962ff32a801

commit r17-4810-g9f7a095e81bd3bafbc0fd66ab210a962ff32a801
Author: Richard Biener <[email protected]>
Date:   Thu Oct 1 09:46:30 2026 +0200

    Fix missed constant folding of .BITREVERSE
    
    This fixes missed constant folding of .BITREVERSE (or other functions
    with _BitInt return value) which was caused due to a SCALAR_INT_MODE_P
    that fails on BLKmode _BitInt types.  Replace this with checking
    the return type rather than its mode which isn't used anyway.
    
            * fold-const-call.cc (fold_const_call_1): Check the
            return type rather than the mode for a scalar integral
            type before dispatching to fold_const_call_ss and
            fold_const_call_sss.
    
            * gcc.dg/tree-ssa/ssa-ccp-45.c: New testcase.

Diff:
---
 gcc/fold-const-call.cc                     |  4 ++--
 gcc/testsuite/gcc.dg/tree-ssa/ssa-ccp-45.c | 16 ++++++++++++++++
 2 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/gcc/fold-const-call.cc b/gcc/fold-const-call.cc
index 94841e8fb65c..c04e93ce2eec 100644
--- a/gcc/fold-const-call.cc
+++ b/gcc/fold-const-call.cc
@@ -1311,7 +1311,7 @@ fold_const_call_1 (combined_fn fn, tree type, tree arg)
 
   if (integer_cst_p (arg))
     {
-      if (SCALAR_INT_MODE_P (mode))
+      if (INTEGRAL_TYPE_P (type))
        {
          wide_int result;
          if (fold_const_call_ss (&result, fn, wi::to_wide (arg),
@@ -1762,7 +1762,7 @@ fold_const_call_1 (combined_fn fn, tree type, tree arg0, 
tree arg1)
 
   if (integer_cst_p (arg0) && integer_cst_p (arg1))
     {
-      if (SCALAR_INT_MODE_P (mode))
+      if (INTEGRAL_TYPE_P (type))
        {
          wide_int result;
          if (fold_const_call_sss (&result, fn, wi::to_wide (arg0),
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/ssa-ccp-45.c 
b/gcc/testsuite/gcc.dg/tree-ssa/ssa-ccp-45.c
new file mode 100644
index 000000000000..ea3c73350e7f
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/ssa-ccp-45.c
@@ -0,0 +1,16 @@
+/* { dg-do compile { target bitint } } */
+/* { dg-options "-O -fdump-tree-ccp1" } */
+
+#if __BITINT_MAXWIDTH__ >= 129
+typedef unsigned _BitInt(129) T;
+
+T
+foo ()
+{
+  T y = (T) 1;
+  T x = __builtin_bitreverseg (y);
+  return x;
+}
+#endif
+
+/* { dg-final { scan-tree-dump-not "BITREVERSE" "ccp1" } } */

Reply via email to