* [Bug rtl-optimization/105376] ICE: in decimal_to_decnumber, at dfp.cc:134 with _Decimal128 at -O -g
2022-04-25 13:21 [Bug rtl-optimization/105376] New: ICE: in decimal_to_decnumber, at dfp.cc:134 with _Decimal128 at -O -g zsojka at seznam dot cz
@ 2022-04-25 13:23 ` marxin at gcc dot gnu.org
2022-04-26 6:48 ` rguenth at gcc dot gnu.org
` (7 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: marxin at gcc dot gnu.org @ 2022-04-25 13:23 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105376
Martin Liška <marxin at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Last reconfirmed| |2022-04-25
CC| |marxin at gcc dot gnu.org
Ever confirmed|0 |1
Status|UNCONFIRMED |NEW
--- Comment #1 from Martin Liška <marxin at gcc dot gnu.org> ---
It's there at least since GCC 4.8.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug rtl-optimization/105376] ICE: in decimal_to_decnumber, at dfp.cc:134 with _Decimal128 at -O -g
2022-04-25 13:21 [Bug rtl-optimization/105376] New: ICE: in decimal_to_decnumber, at dfp.cc:134 with _Decimal128 at -O -g zsojka at seznam dot cz
2022-04-25 13:23 ` [Bug rtl-optimization/105376] " marxin at gcc dot gnu.org
@ 2022-04-26 6:48 ` rguenth at gcc dot gnu.org
2022-04-26 17:56 ` joseph at codesourcery dot com
` (6 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-04-26 6:48 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105376
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |jsm28 at gcc dot gnu.org,
| |rguenth at gcc dot gnu.org
--- Comment #2 from Richard Biener <rguenth at gcc dot gnu.org> ---
(gdb) p debug_rtx (rtl)
(const_double:TD -2.0e+0 [-0x0.8p+2])
but CONST_DOUBLE_REAL_VALUE (rtl) has ->recimal == false, and that's true even
on
the tree level. Generated by
/* Convert x+x into x*2. */
(simplify
(plus @0 @0)
(if (SCALAR_FLOAT_TYPE_P (type))
(mult @0 { build_real (type, dconst2); })
(if (INTEGRAL_TYPE_P (type))
(mult @0 { build_int_cst (type, 2); }))))
where indeed the dconst2 is not decimal. I have no idea how to create a DFP
constant, but I guess that in priciple (at least for dconst2), creating
the constant with double_type_node and then fold-converting to type might work?
It just looks like a bit much of work ...
Joseph, do you have any insights here? The above is of course copied from
fold-const.cc originally.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug rtl-optimization/105376] ICE: in decimal_to_decnumber, at dfp.cc:134 with _Decimal128 at -O -g
2022-04-25 13:21 [Bug rtl-optimization/105376] New: ICE: in decimal_to_decnumber, at dfp.cc:134 with _Decimal128 at -O -g zsojka at seznam dot cz
2022-04-25 13:23 ` [Bug rtl-optimization/105376] " marxin at gcc dot gnu.org
2022-04-26 6:48 ` rguenth at gcc dot gnu.org
@ 2022-04-26 17:56 ` joseph at codesourcery dot com
2022-04-27 6:27 ` rguenth at gcc dot gnu.org
` (5 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: joseph at codesourcery dot com @ 2022-04-26 17:56 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105376
--- Comment #3 from joseph at codesourcery dot com <joseph at codesourcery dot com> ---
For this transformation to be correct for DFP, you need a 2 with quantum
exponent 0. Converting from either integer or binary floating-point 2
will work for that. However, I note that decimal_to_decnumber has
case rvc_normal:
if (!r->decimal)
{
/* dconst{1,2,m1,half} are used in various places in
the middle-end and optimizers, allow them here
as an exception by converting them to decimal. */
so the existing code ought to work as-is. Maybe there is a problem with
padding in REAL_VALUE_TYPE meaning the comparisons don't work as intended?
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug rtl-optimization/105376] ICE: in decimal_to_decnumber, at dfp.cc:134 with _Decimal128 at -O -g
2022-04-25 13:21 [Bug rtl-optimization/105376] New: ICE: in decimal_to_decnumber, at dfp.cc:134 with _Decimal128 at -O -g zsojka at seznam dot cz
` (2 preceding siblings ...)
2022-04-26 17:56 ` joseph at codesourcery dot com
@ 2022-04-27 6:27 ` rguenth at gcc dot gnu.org
2022-04-27 6:31 ` rguenth at gcc dot gnu.org
` (4 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-04-27 6:27 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105376
--- Comment #4 from Richard Biener <rguenth at gcc dot gnu.org> ---
(In reply to joseph@codesourcery.com from comment #3)
> For this transformation to be correct for DFP, you need a 2 with quantum
> exponent 0. Converting from either integer or binary floating-point 2
> will work for that. However, I note that decimal_to_decnumber has
>
> case rvc_normal:
> if (!r->decimal)
> {
> /* dconst{1,2,m1,half} are used in various places in
> the middle-end and optimizers, allow them here
> as an exception by converting them to decimal. */
>
> so the existing code ought to work as-is. Maybe there is a problem with
> padding in REAL_VALUE_TYPE meaning the comparisons don't work as intended?
It ends up as -dconst2 in the end which isn't handled.
(gdb) p *r
$1 = {cl = 1, decimal = 0, sign = 1, signalling = 0, canonical = 0, uexp = 2,
sig = {0, 0, 9223372036854775808}}
(gdb) p dconst2
$2 = {cl = 1, decimal = 0, sign = 0, signalling = 0, canonical = 0, uexp = 2,
sig = {0, 0, 9223372036854775808}}
So the initial transform of x+x to 2.*x is "OK" in that this "wrong" 2.
is handled but followup transforms rely on 2. being correct, specifically
fold_negate_const just does
case REAL_CST:
t = build_real (type, real_value_negate (&TREE_REAL_CST (arg0)));
break;
without considering that the TREE_REAL_CST isn't appropriate for 'type'.
It looks like using build_real_truncate instead of build_real works as well,
so that's what I am going to do for this PR. There's a lot of
'build_real .*dconst' in match.pd that would need a similar fix so I wonder
if build_real should special-case those or if we should get rid of the
dconst* REAL_VALUE_TYPE and instead use an overload from int using a
more fancy way of caching.
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); }))))
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug rtl-optimization/105376] ICE: in decimal_to_decnumber, at dfp.cc:134 with _Decimal128 at -O -g
2022-04-25 13:21 [Bug rtl-optimization/105376] New: ICE: in decimal_to_decnumber, at dfp.cc:134 with _Decimal128 at -O -g zsojka at seznam dot cz
` (3 preceding siblings ...)
2022-04-27 6:27 ` rguenth at gcc dot gnu.org
@ 2022-04-27 6:31 ` rguenth at gcc dot gnu.org
2022-04-29 6:17 ` cvs-commit at gcc dot gnu.org
` (3 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-04-27 6:31 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105376
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Assignee|unassigned at gcc dot gnu.org |rguenth at gcc dot gnu.org
Status|NEW |ASSIGNED
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug rtl-optimization/105376] ICE: in decimal_to_decnumber, at dfp.cc:134 with _Decimal128 at -O -g
2022-04-25 13:21 [Bug rtl-optimization/105376] New: ICE: in decimal_to_decnumber, at dfp.cc:134 with _Decimal128 at -O -g zsojka at seznam dot cz
` (4 preceding siblings ...)
2022-04-27 6:31 ` rguenth at gcc dot gnu.org
@ 2022-04-29 6:17 ` cvs-commit at gcc dot gnu.org
2022-04-29 6:18 ` rguenth at gcc dot gnu.org
` (2 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-04-29 6:17 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105376
--- Comment #5 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Richard Biener <rguenth@gcc.gnu.org>:
https://gcc.gnu.org/g:e27eef7478f30ea79048dbde3317e89679d75a6e
commit r13-27-ge27eef7478f30ea79048dbde3317e89679d75a6e
Author: Richard Biener <rguenther@suse.de>
Date: Wed Apr 27 08:28:31 2022 +0200
middle-end/105376 - invalid REAL_CST for DFP constant
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 extends the decimal_to_decnumber
special-casing of dconst* to build_real, avoiding the bogus REAL_CSTs
from creeping into the IL and modified to ones not handled by
the decimal_to_decnumber special casing. It also makes sure to
ICE for not handled dconst* values at the point we build the REAL_CST.
2022-04-27 Richard Biener <rguenther@suse.de>
PR middle-end/105376
* tree.cc (build_real): Special case dconst* arguments
for decimal floating point types.
* gcc.dg/pr105376.c: New testcase.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug rtl-optimization/105376] ICE: in decimal_to_decnumber, at dfp.cc:134 with _Decimal128 at -O -g
2022-04-25 13:21 [Bug rtl-optimization/105376] New: ICE: in decimal_to_decnumber, at dfp.cc:134 with _Decimal128 at -O -g zsojka at seznam dot cz
` (5 preceding siblings ...)
2022-04-29 6:17 ` cvs-commit at gcc dot gnu.org
@ 2022-04-29 6:18 ` rguenth at gcc dot gnu.org
2022-05-06 10:30 ` cvs-commit at gcc dot gnu.org
2022-07-22 9:49 ` rguenth at gcc dot gnu.org
8 siblings, 0 replies; 10+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-04-29 6:18 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105376
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Known to work| |13.0
--- Comment #6 from Richard Biener <rguenth at gcc dot gnu.org> ---
Fixed on trunk sofar, I'm considering backporting this at a later point.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug rtl-optimization/105376] ICE: in decimal_to_decnumber, at dfp.cc:134 with _Decimal128 at -O -g
2022-04-25 13:21 [Bug rtl-optimization/105376] New: ICE: in decimal_to_decnumber, at dfp.cc:134 with _Decimal128 at -O -g zsojka at seznam dot cz
` (6 preceding siblings ...)
2022-04-29 6:18 ` rguenth at gcc dot gnu.org
@ 2022-05-06 10:30 ` cvs-commit at gcc dot gnu.org
2022-07-22 9:49 ` rguenth at gcc dot gnu.org
8 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-05-06 10:30 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105376
--- Comment #7 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-12 branch has been updated by Richard Biener
<rguenth@gcc.gnu.org>:
https://gcc.gnu.org/g:39c56695c70a2052fc6bdcfca606dfff9c2fa975
commit r12-8348-g39c56695c70a2052fc6bdcfca606dfff9c2fa975
Author: Richard Biener <rguenther@suse.de>
Date: Wed Apr 27 08:28:31 2022 +0200
middle-end/105376 - invalid REAL_CST for DFP constant
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 extends the decimal_to_decnumber
special-casing of dconst* to build_real, avoiding the bogus REAL_CSTs
from creeping into the IL and modified to ones not handled by
the decimal_to_decnumber special casing. It also makes sure to
ICE for not handled dconst* values at the point we build the REAL_CST.
2022-04-27 Richard Biener <rguenther@suse.de>
PR middle-end/105376
* tree.cc (build_real): Special case dconst* arguments
for decimal floating point types.
* gcc.dg/pr105376.c: New testcase.
(cherry picked from commit e27eef7478f30ea79048dbde3317e89679d75a6e)
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug rtl-optimization/105376] ICE: in decimal_to_decnumber, at dfp.cc:134 with _Decimal128 at -O -g
2022-04-25 13:21 [Bug rtl-optimization/105376] New: ICE: in decimal_to_decnumber, at dfp.cc:134 with _Decimal128 at -O -g zsojka at seznam dot cz
` (7 preceding siblings ...)
2022-05-06 10:30 ` cvs-commit at gcc dot gnu.org
@ 2022-07-22 9:49 ` rguenth at gcc dot gnu.org
8 siblings, 0 replies; 10+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-07-22 9:49 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105376
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |FIXED
Status|ASSIGNED |RESOLVED
--- Comment #8 from Richard Biener <rguenth at gcc dot gnu.org> ---
Fixed for GCC 12.2, not a regression.
^ permalink raw reply [flat|nested] 10+ messages in thread