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.
Bootstrapped on x86_64-unknown-linux-gnu, testing in progress.
OK if that passes?
I didn't quite understand where you wanted extra checks - given
that 'arg' is integer_cst_p its mode will surely be scalar integer
if it isn't a BIT_INT_TYPE(?).
Thanks,
Richard.
* 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.
* gcc.dg/tree-ssa/ssa-ccp-45.c: New testcase.
---
gcc/fold-const-call.cc | 2 +-
gcc/testsuite/gcc.dg/tree-ssa/ssa-ccp-45.c | 16 ++++++++++++++++
2 files changed, 17 insertions(+), 1 deletion(-)
create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/ssa-ccp-45.c
diff --git a/gcc/fold-const-call.cc b/gcc/fold-const-call.cc
index 94841e8fb65..2a8316bf406 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),
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 00000000000..ea3c73350e7
--- /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" } } */
--
2.51.0