]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
vr-values: Avoid ICEs on large _BitInt cast to floating point [PR112901]
authorJakub Jelinek <jakub@redhat.com>
Fri, 8 Dec 2023 08:02:15 +0000 (09:02 +0100)
committerJakub Jelinek <jakub@redhat.com>
Fri, 8 Dec 2023 08:02:15 +0000 (09:02 +0100)
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.

gcc/testsuite/gcc.dg/bitint-51.c [new file with mode: 0644]
gcc/vr-values.cc

diff --git a/gcc/testsuite/gcc.dg/bitint-51.c b/gcc/testsuite/gcc.dg/bitint-51.c
new file mode 100644 (file)
index 0000000..0574070
--- /dev/null
@@ -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
index ecb294131b06ba90ec8edf02f276d9b9fe0077af..711538912aa85a69fac578a1811e855e93d52c8e 100644 (file)
@@ -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))