From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 812CC3858405; Wed, 27 Apr 2022 06:27:13 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 812CC3858405 From: "rguenth at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug rtl-optimization/105376] ICE: in decimal_to_decnumber, at dfp.cc:134 with _Decimal128 at -O -g Date: Wed, 27 Apr 2022 06:27:12 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: rtl-optimization X-Bugzilla-Version: 12.0 X-Bugzilla-Keywords: ice-on-valid-code X-Bugzilla-Severity: normal X-Bugzilla-Who: rguenth at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 27 Apr 2022 06:27:13 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D105376 --- Comment #4 from Richard Biener --- (In reply to joseph@codesourcery.com from comment #3) > For this transformation to be correct for DFP, you need a 2 with quantum= =20 > exponent 0. Converting from either integer or binary floating-point 2=20 > will work for that. However, I note that decimal_to_decnumber has >=20 > 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. */ >=20 > so the existing code ought to work as-is. Maybe there is a problem with= =20 > 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 =3D {cl =3D 1, decimal =3D 0, sign =3D 1, signalling =3D 0, canonical = =3D 0, uexp =3D 2,=20 sig =3D {0, 0, 9223372036854775808}} (gdb) p dconst2 $2 =3D {cl =3D 1, decimal =3D 0, sign =3D 0, signalling =3D 0, canonical = =3D 0, uexp =3D 2,=20 sig =3D {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 =3D 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); }))))=