From b5cfbb8f4cceb621d6812eec3e0fb876b648241c Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Fri, 8 Dec 2023 09:02:15 +0100 Subject: [PATCH] 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 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 | 14 ++++++++++++++ gcc/vr-values.cc | 5 +++++ 2 files changed, 19 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/bitint-51.c 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)) -- 2.11.4.GIT