public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug rtl-optimization/105376] New: ICE: in decimal_to_decnumber, at dfp.cc:134 with _Decimal128 at -O -g
@ 2022-04-25 13:21 zsojka at seznam dot cz
  2022-04-25 13:23 ` [Bug rtl-optimization/105376] " marxin at gcc dot gnu.org
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: zsojka at seznam dot cz @ 2022-04-25 13:21 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105376

            Bug ID: 105376
           Summary: ICE: in decimal_to_decnumber, at dfp.cc:134 with
                    _Decimal128 at -O -g
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Keywords: ice-on-valid-code
          Severity: normal
          Priority: P3
         Component: rtl-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: zsojka at seznam dot cz
  Target Milestone: ---
              Host: x86_64-pc-linux-gnu

Created attachment 52868
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=52868&action=edit
reduced testcase

Compiler output:
$ x86_64-pc-linux-gnu-gcc -O -g testcase.c 
during RTL pass: final
testcase.c: In function 'foo':
testcase.c:6:1: internal compiler error: in decimal_to_decnumber, at dfp.cc:134
    6 | }
      | ^
0x22f0853 decimal_to_decnumber
        /repo/gcc-trunk/gcc/dfp.cc:134
0x22f0adf encode_decimal128(real_format const*, long*, real_value const*)
        /repo/gcc-trunk/gcc/dfp.cc:269
0x12e6585 real_to_target(long*, real_value const*, format_helper)
        /repo/gcc-trunk/gcc/real.cc:2838
0xf1d9b3 insert_float
        /repo/gcc-trunk/gcc/dwarf2out.cc:20173
0xf560d6 mem_loc_descriptor(rtx_def*, machine_mode, machine_mode,
var_init_status)
        /repo/gcc-trunk/gcc/dwarf2out.cc:16654
0xf5642e mem_loc_descriptor(rtx_def*, machine_mode, machine_mode,
var_init_status)
        /repo/gcc-trunk/gcc/dwarf2out.cc:16481
0xf563c9 mem_loc_descriptor(rtx_def*, machine_mode, machine_mode,
var_init_status)
        /repo/gcc-trunk/gcc/dwarf2out.cc:16470
0xf5b30a loc_descriptor
        /repo/gcc-trunk/gcc/dwarf2out.cc:17357
0xf5b70a dw_loc_list_1
        /repo/gcc-trunk/gcc/dwarf2out.cc:17460
0xf5bc59 dw_loc_list
        /repo/gcc-trunk/gcc/dwarf2out.cc:17743
0xf51819 loc_list_from_tree_1
        /repo/gcc-trunk/gcc/dwarf2out.cc:18939
0xf6198d loc_list_from_tree
        /repo/gcc-trunk/gcc/dwarf2out.cc:19642
0xf6198d add_location_or_const_value_attribute
        /repo/gcc-trunk/gcc/dwarf2out.cc:20861
0xf61ca7 gen_formal_parameter_die
        /repo/gcc-trunk/gcc/dwarf2out.cc:22966
0xf44425 gen_subprogram_die
        /repo/gcc-trunk/gcc/dwarf2out.cc:23978
0xf4911c gen_decl_die
        /repo/gcc-trunk/gcc/dwarf2out.cc:26977
0xf4a12b dwarf2out_decl
        /repo/gcc-trunk/gcc/dwarf2out.cc:27555
0xf4a5de dwarf2out_function_decl
        /repo/gcc-trunk/gcc/dwarf2out.cc:27570
0xfd16e2 rest_of_handle_final
        /repo/gcc-trunk/gcc/final.cc:4321
0xfd16e2 execute
        /repo/gcc-trunk/gcc/final.cc:4363
Please submit a full bug report, with preprocessed source (by using
-freport-bug).
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.

$ x86_64-pc-linux-gnu-gcc -v
Using built-in specs.
COLLECT_GCC=/repo/gcc-trunk/binary-latest-amd64/bin/x86_64-pc-linux-gnu-gcc
COLLECT_LTO_WRAPPER=/repo/gcc-trunk/binary-trunk-r12-8242-20220425114659-gf0e170f72f8-checking-yes-rtl-df-extra-nobootstrap-amd64/bin/../libexec/gcc/x86_64-pc-linux-gnu/12.0.1/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /repo/gcc-trunk//configure --enable-languages=c,c++
--enable-valgrind-annotations --disable-nls --enable-checking=yes,rtl,df,extra
--disable-bootstrap --with-cloog --with-ppl --with-isl
--build=x86_64-pc-linux-gnu --host=x86_64-pc-linux-gnu
--target=x86_64-pc-linux-gnu --with-ld=/usr/bin/x86_64-pc-linux-gnu-ld
--with-as=/usr/bin/x86_64-pc-linux-gnu-as --disable-libstdcxx-pch
--prefix=/repo/gcc-trunk//binary-trunk-r12-8242-20220425114659-gf0e170f72f8-checking-yes-rtl-df-extra-nobootstrap-amd64
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 12.0.1 20220425 (experimental) (GCC)

^ 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 ` 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

end of thread, other threads:[~2022-07-22  9:49 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
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
2022-05-06 10:30 ` cvs-commit at gcc dot gnu.org
2022-07-22  9:49 ` rguenth at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).