Bug 105263 - [10 Regression] ICE: gimple check: expected gimple_assign(error_mark), have gimple_nop() in gimple_assign_rhs1, at gimple.h:2655 with _Decimal64 -ffast-math since r7-950-g8a85cee26eabf5cf
Summary: [10 Regression] ICE: gimple check: expected gimple_assign(error_mark), have g...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 12.0
: P2 normal
Target Milestone: 11.4
Assignee: Richard Biener
URL:
Keywords: ice-on-valid-code
Depends on:
Blocks:
 
Reported: 2022-04-13 12:18 UTC by Zdenek Sojka
Modified: 2023-07-07 09:59 UTC (History)
1 user (show)

See Also:
Host: x86_64-pc-linux-gnu
Target:
Build:
Known to work: 11.3.1, 12.0, 5.5.0, 6.5.0
Known to fail: 10.3.1, 10.5.0, 11.3.0, 12.0, 7.5.0, 8.5.0, 9.4.1
Last reconfirmed: 2022-04-13 00:00:00


Attachments
reduced testcase (128 bytes, text/plain)
2022-04-13 12:18 UTC, Zdenek Sojka
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Zdenek Sojka 2022-04-13 12:18:15 UTC
Created attachment 52800 [details]
reduced testcase

Compiler output:
$ x86_64-pc-linux-gnu-gcc -O -ffast-math testcase.c 
during GIMPLE pass: reassoc
testcase.c: In function 'foo':
testcase.c:7:1: internal compiler error: gimple check: expected gimple_assign(error_mark), have gimple_nop() in gimple_assign_rhs1, at gimple.h:2655
    7 | foo (U u)
      | ^~~
0x6e6c4d gimple_check_failed(gimple const*, char const*, int, char const*, gimple_code, tree_code)
        /repo/gcc-trunk/gcc/gimple.cc:1292
0x7d830d GIMPLE_CHECK2<const gassign*>
        /repo/gcc-trunk/gcc/gimple.h:74
0x7d833d GIMPLE_CHECK2<const gassign*>
        /repo/gcc-trunk/gcc/gimple.h:2653
0x7d833d gimple_assign_rhs1
        /repo/gcc-trunk/gcc/gimple.h:2655
0x7d886f gimple_assign_rhs1
        /repo/gcc-trunk/gcc/tree.h:3571
0x7d886f rewrite_expr_tree
        /repo/gcc-trunk/gcc/tree-ssa-reassoc.cc:5248
0x155514e rewrite_expr_tree
        /repo/gcc-trunk/gcc/tree-ssa-reassoc.cc:5339
0x155514e rewrite_expr_tree
        /repo/gcc-trunk/gcc/tree-ssa-reassoc.cc:5339
0x15665fa reassociate_bb
        /repo/gcc-trunk/gcc/tree-ssa-reassoc.cc:6848
0x156593a reassociate_bb
        /repo/gcc-trunk/gcc/tree-ssa-reassoc.cc:6897
0x1567ede do_reassoc
        /repo/gcc-trunk/gcc/tree-ssa-reassoc.cc:7009
0x1567ede execute_reassoc
        /repo/gcc-trunk/gcc/tree-ssa-reassoc.cc:7098
0x1567ede execute
        /repo/gcc-trunk/gcc/tree-ssa-reassoc.cc:7139
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-8113-20220412190241-gaa7874596b9-checking-yes-rtl-df-extra-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 --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-8113-20220412190241-gaa7874596b9-checking-yes-rtl-df-extra-amd64
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 12.0.1 20220412 (experimental) (GCC)
Comment 1 Martin Liška 2022-04-13 12:44:40 UTC
Started with r7-950-g8a85cee26eabf5cf.
Comment 2 Richard Biener 2022-04-13 12:52:00 UTC
Confirmed.

5336      /* Recurse on the LHS of the binary operator, which is guaranteed to
5337         be the non-leaf side.  */
5338      tree new_rhs1
5339        = rewrite_expr_tree (SSA_NAME_DEF_STMT (rhs1), rhs_code, opindex + 1, ops,
5340                             changed || oe->op != rhs2 || next_changed,
5341                             false);

but in this case it's the leaf side...

(gdb) p debug_gimple_stmt (stmt)
u_3 = u_2(D) * u_2(D);

(gdb) p debug_generic_expr (ops.m_vec->m_vecdata[0]->op)
u_2(D)
$11 = void
(gdb) p debug_generic_expr (ops.m_vec->m_vecdata[1]->op)
u_2(D)
$12 = void
(gdb) p debug_generic_expr (ops.m_vec->m_vecdata[2]->op)
_5
$13 = void
(gdb) p debug_generic_expr (ops.m_vec->m_vecdata[3]->op)
{ -1.0e+0 }

U foo (U u)
{
  _Decimal64 _1;
  U _5;
  vector(1) _Decimal64 _6;

  <bb 2> [local count: 1073741824]:
  u_3 = u_2(D) * u_2(D);
  _1 = BIT_FIELD_REF <v(address-taken), 64, 64>;
  _5 = {_1};
  _6 = -_5;
  u_7 = u_3 * _6;
  <retval> = u_7;
  return <retval>;

so basically the multiplication by -1 trick to handle the negation
breaks the left associativity rewrite because we need to go too deep.

Tricky.

Supposedly we have to pop the -1 before rewriting the expression
but we fail.  We fail because build_minus_one_cst doesn't build something
real_minus_onep, in this case the VECTOR_CST part, recognizes.  And
that's because of

3156    bool
3157    real_minus_onep (const_tree expr)
...
3164          return real_equal (&TREE_REAL_CST (expr), &dconstm1)
3165                 && !(DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (expr))));

means we have to exclude _Decimal modes from this trick.
Comment 3 GCC Commits 2022-04-13 13:59:35 UTC
The master branch has been updated by Richard Biener <rguenth@gcc.gnu.org>:

https://gcc.gnu.org/g:ca145c6306f19272ac8756d88c4eba0bfdf01dfb

commit r12-8142-gca145c6306f19272ac8756d88c4eba0bfdf01dfb
Author: Richard Biener <rguenther@suse.de>
Date:   Wed Apr 13 14:53:40 2022 +0200

    tree-optimization/105263 - reassoc and DFP
    
    reassoc has certain tricks which in the end depend on the ability
    to undo them.  For DFP creating a -1. constant is easy but
    re-identifying is appearantly not - real_minus_onep rejects those
    outright for DFP.  So we have to disable (at least) this one trick.
    
    2022-04-13  Richard Biener  <rguenther@suse.de>
    
            PR tree-optimization/105263
            * tree-ssa-reassoc.cc (try_special_add_to_ops): Do not consume
            negates in multiplication chains with DFP.
    
            * gcc.dg/pr105263.c: New testcase.
Comment 4 Richard Biener 2022-04-13 14:00:03 UTC
Fixed on trunk sofar.
Comment 5 GCC Commits 2022-05-19 14:03:21 UTC
The releases/gcc-11 branch has been updated by Richard Biener <rguenth@gcc.gnu.org>:

https://gcc.gnu.org/g:b2557f9081e5bf440abe3fc184cbdaea0447ec64

commit r11-10017-gb2557f9081e5bf440abe3fc184cbdaea0447ec64
Author: Richard Biener <rguenther@suse.de>
Date:   Wed Apr 13 14:53:40 2022 +0200

    tree-optimization/105263 - reassoc and DFP
    
    reassoc has certain tricks which in the end depend on the ability
    to undo them.  For DFP creating a -1. constant is easy but
    re-identifying is appearantly not - real_minus_onep rejects those
    outright for DFP.  So we have to disable (at least) this one trick.
    
    2022-04-13  Richard Biener  <rguenther@suse.de>
    
            PR tree-optimization/105263
            * tree-ssa-reassoc.c (try_special_add_to_ops): Do not consume
            negates in multiplication chains with DFP.
    
            * gcc.dg/pr105263.c: New testcase.
    
    (cherry picked from commit ca145c6306f19272ac8756d88c4eba0bfdf01dfb)
Comment 6 Richard Biener 2022-05-27 09:48:01 UTC
GCC 9 branch is being closed
Comment 7 Jakub Jelinek 2022-06-28 10:49:04 UTC
GCC 10.4 is being released, retargeting bugs to GCC 10.5.
Comment 8 Richard Biener 2023-07-07 09:59:10 UTC
Fixed in 11.4.