[gcc r14-6306] vr-values: Avoid ICEs on large _BitInt cast to floating point [PR112901]

Jakub Jelinek jakub@gcc.gnu.org
Fri Dec 8 08:02:50 GMT 2023


https://gcc.gnu.org/g:b5cfbb8f4cceb621d6812eec3e0fb876b648241c

commit r14-6306-gb5cfbb8f4cceb621d6812eec3e0fb876b648241c
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Fri Dec 8 09:02:15 2023 +0100

    vr-values: Avoid ICEs on large _BitInt cast to floating point [PR112901]
    
    For casts from integers to floating point,
    simplify_float_conversion_using_ranges uses SCALAR_INT_TYPE_MODE
    and queries optabs on the optimization it wants to make.
    
    That doesn't really work for large/huge BITINT_TYPE, those have BLKmode
    which is not scalar int mode.  Querying an optab is not useful for that
    either.
    
    I think it is best to just skip this optimization for those bitints,
    after all, bitint lowering uses ranges already to determine minimum
    precision for bitint operands of the integer to float casts.
    
    2023-12-08  Jakub Jelinek  <jakub@redhat.com>
    
            PR tree-optimization/112901
            * vr-values.cc
            (simplify_using_ranges::simplify_float_conversion_using_ranges):
            Return false if rhs1 has BITINT_TYPE type with BLKmode TYPE_MODE.
    
            * gcc.dg/bitint-51.c: New test.

Diff:
---
 gcc/testsuite/gcc.dg/bitint-51.c | 14 ++++++++++++++
 gcc/vr-values.cc                 |  5 +++++
 2 files changed, 19 insertions(+)

diff --git a/gcc/testsuite/gcc.dg/bitint-51.c b/gcc/testsuite/gcc.dg/bitint-51.c
new file mode 100644
index 00000000000..057407099e4
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/bitint-51.c
@@ -0,0 +1,14 @@
+/* PR tree-optimization/112901 */
+/* { dg-do compile { target bitint } } */
+/* { dg-options "-O2" } */
+
+float f;
+#if __BITINT_MAXWIDTH__ >= 256
+_BitInt(256) i;
+
+void
+foo (void)
+{
+  f *= 4 * i;
+}
+#endif
diff --git a/gcc/vr-values.cc b/gcc/vr-values.cc
index ecb294131b0..711538912aa 100644
--- a/gcc/vr-values.cc
+++ b/gcc/vr-values.cc
@@ -1656,6 +1656,11 @@ simplify_using_ranges::simplify_float_conversion_using_ranges
       || vr.undefined_p ())
     return false;
 
+  /* The code below doesn't work for large/huge _BitInt, nor is really
+     needed for those, bitint lowering does use ranges already.  */
+  if (TREE_CODE (TREE_TYPE (rhs1)) == BITINT_TYPE
+      && TYPE_MODE (TREE_TYPE (rhs1)) == BLKmode)
+    return false;
   /* First check if we can use a signed type in place of an unsigned.  */
   scalar_int_mode rhs_mode = SCALAR_INT_TYPE_MODE (TREE_TYPE (rhs1));
   if (TYPE_UNSIGNED (TREE_TYPE (rhs1))


More information about the Gcc-cvs mailing list