We are eventually ICEing in decimal_to_decnumber on non-decimal
REAL_VALUE_TYPE that creep in from uses of build_real (..., dconst*)
for DFP types.  The following fixes the single occurance that matters
for the testcase in the PR by instead using build_real_truncate.

Bootstrapped and tested on x86_64-unknown-linux-gnu.

OK for trunk?

Is this the correct strathegy to deal with this problem?  Would
it be valid to just set ->is_decimal in build_real based on
DECIMAL_FLOAT_TYPE_P for the dconst* cases we "support" (not
checking for them but instead declaring others invalid)?

Richard.

2022-04-27  Richard Biener  <rguent...@suse.de>

        PR middle-end/105376
        * match.pd (x + x -> 2.*x): Use build_real_truncate.

        * gcc.dg/pr105376.c: New testcase.
---
 gcc/match.pd                    | 2 +-
 gcc/testsuite/gcc.dg/pr105376.c | 9 +++++++++
 2 files changed, 10 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gcc.dg/pr105376.c

diff --git a/gcc/match.pd b/gcc/match.pd
index 6d691d302b3..663dccf3289 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -3865,7 +3865,7 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
 (simplify
  (plus @0 @0)
  (if (SCALAR_FLOAT_TYPE_P (type))
-  (mult @0 { build_real (type, dconst2); })
+  (mult @0 { build_real_truncate (type, dconst2); })
   (if (INTEGRAL_TYPE_P (type))
    (mult @0 { build_int_cst (type, 2); }))))
 
diff --git a/gcc/testsuite/gcc.dg/pr105376.c b/gcc/testsuite/gcc.dg/pr105376.c
new file mode 100644
index 00000000000..f19ecf4aab2
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr105376.c
@@ -0,0 +1,9 @@
+/* { dg-do compile { target dfp } } */
+/* { dg-options "-O -g" } */
+
+void
+foo (_Decimal64 d, _Decimal64 e)
+{
+  d -= -d;
+  d *= -e;
+}
-- 
2.34.1

Reply via email to