Bug 96370 - [8 Regression] ICE with -ffast-math since r7-950-g8a85cee26eabf5cf
Summary: [8 Regression] ICE with -ffast-math since r7-950-g8a85cee26eabf5cf
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 11.0
: P2 normal
Target Milestone: 8.5
Assignee: Richard Biener
URL:
Keywords: ice-on-valid-code
Depends on:
Blocks: 96579
  Show dependency treegraph
 
Reported: 2020-07-29 14:23 UTC by David Binderman
Modified: 2021-03-17 11:15 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work: 10.2.1, 11.0, 8.4.1, 9.3.1
Known to fail: 10.2.0, 8.4.0, 9.3.0
Last reconfirmed: 2020-07-30 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description David Binderman 2020-07-29 14:23:42 UTC
Recent gcc trunk, with this C source code:

a() {
  _Decimal128 b;
  c(-b * b);
}

and compiler flag -O2 -ffast-math, does this:

during GIMPLE pass: reassoc
bug633.c: In function ‘a’:
bug633.c:1:1: internal compiler error: in gimple_build_assign_1, at gimple.c:455
    1 | a() {
      | ^
0x96e82e gimple_build_assign_1(tree_node*, tree_code, tree_node*, tree_node*, tr
ee_node*)
	../../trunk.git/gcc/gimple.c:455
0xec0a0b rewrite_expr_tree(gimple*, unsigned int, vec<operand_entry*, va_heap, v
l_ptr>, bool, bool)
	../../trunk.git/gcc/tree-ssa-reassoc.c:4963
0xec0828 rewrite_expr_tree(gimple*, unsigned int, vec<operand_entry*, va_heap, v
l_ptr>, bool, bool)
	../../trunk.git/gcc/tree-ssa-reassoc.c:5007
0xeb6d9e reassociate_bb(basic_block_def*)
	../../trunk.git/gcc/tree-ssa-reassoc.c:6480

The bug seems to have existed since sometime before 20200630.

Thanks to cvise for reducing the code quickly.
Comment 1 Richard Biener 2020-07-30 06:00:19 UTC
Confirmed.

#1  0x0000000000e1d0d9 in gimple_build_assign_1 (lhs=
    <ssa_name 0x7ffff6574f30 6>, subcode=NEGATE_EXPR, 
    op1=<ssa_name 0x7ffff6574d80 3>, op2=<ssa_name 0x7ffff6574d80 3>, 
    op3=<tree 0x0>) at ../../src/test/gcc/gimple.c:455
455           gcc_assert (num_ops > 2);

#3  0x00000000016294ee in rewrite_expr_tree (
    stmt=<gimple_assign 0x7ffff66adaa0>, opindex=1, ops=..., changed=true, 
    next_changed=false) at ../../src/test/gcc/tree-ssa-reassoc.c:4963
4963                    = gimple_build_assign (lhs, gimple_assign_rhs_code (stmt),
(gdb) l
4958                {
4959                  gimple *insert_point
4960                    = find_insert_point (stmt, oe1->op, oe2->op);
4961                  lhs = make_ssa_name (TREE_TYPE (lhs));
4962                  stmt
4963                    = gimple_build_assign (lhs, gimple_assign_rhs_code (stmt),
4964                                           oe1->op, oe2->op);

so the rhs code is a negate while we expect sth else.  I will have a look.
Comment 2 Martin Liška 2020-07-30 07:28:41 UTC
> 
> Thanks to cvise for reducing the code quickly.

Glad to hear you used cvise!
Comment 3 Martin Liška 2020-07-30 07:35:47 UTC
Started with r7-950-g8a85cee26eabf5cf.
Comment 4 Richard Biener 2020-07-30 08:02:54 UTC
More "complete" testcase:

void c(_Decimal128);
void a(_Decimal128 b)
{
  c(-b * b);
}
Comment 5 Richard Biener 2020-07-30 08:15:26 UTC
OK, so rewrite_expr_tree isn't prepared to see ops with a three component
"leaf" as try_special_add_to_ops produces which turns { -b, b } into
{ b, b, -1 }.  Instead it recurses into the apperant non-leaf _1 which
is the negate.

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

But I have a simple fix.
Comment 6 GCC Commits 2020-07-30 09:36:38 UTC
The master branch has been updated by Richard Biener <rguenth@gcc.gnu.org>:

https://gcc.gnu.org/g:2c558d2655cb22f472c83e8296b5cd2a92365cd3

commit r11-2424-g2c558d2655cb22f472c83e8296b5cd2a92365cd3
Author: Richard Biener <rguenther@suse.de>
Date:   Thu Jul 30 10:24:42 2020 +0200

    tree-optimization/96370 - make reassoc expr rewrite more robust
    
    In the face of the more complex tricks in reassoc with respect
    to negate processing it can happen that the expression rewrite
    is fooled to recurse on a leaf and pick up a bogus expression
    code.  The following patch makes the expression rewrite more
    robust in providing the expression code to it directly since
    it is the same for all operations in a chain.
    
    2020-07-30  Richard Biener  <rguenther@suse.de>
    
            PR tree-optimization/96370
            * tree-ssa-reassoc.c (rewrite_expr_tree): Add operation
            code parameter and use it instead of picking it up from
            the stmt that is being rewritten.
            (reassociate_bb): Pass down the operation code.
    
            * gcc.dg/pr96370.c: New testcase.
Comment 7 Richard Biener 2020-07-30 09:46:11 UTC
Fixed on trunk sofar.
Comment 8 GCC Commits 2020-09-11 12:12:12 UTC
The releases/gcc-10 branch has been updated by Richard Biener <rguenth@gcc.gnu.org>:

https://gcc.gnu.org/g:819fc71b49af8366e6b23d2b57ebb6fb66f1a292

commit r10-8748-g819fc71b49af8366e6b23d2b57ebb6fb66f1a292
Author: Richard Biener <rguenther@suse.de>
Date:   Thu Jul 30 10:24:42 2020 +0200

    tree-optimization/96370 - make reassoc expr rewrite more robust
    
    In the face of the more complex tricks in reassoc with respect
    to negate processing it can happen that the expression rewrite
    is fooled to recurse on a leaf and pick up a bogus expression
    code.  The following patch makes the expression rewrite more
    robust in providing the expression code to it directly since
    it is the same for all operations in a chain.
    
    2020-07-30  Richard Biener  <rguenther@suse.de>
    
            PR tree-optimization/96370
            * tree-ssa-reassoc.c (rewrite_expr_tree): Add operation
            code parameter and use it instead of picking it up from
            the stmt that is being rewritten.
            (reassociate_bb): Pass down the operation code.
    
            * gcc.dg/pr96370.c: New testcase.
    
    (cherry picked from commit 2c558d2655cb22f472c83e8296b5cd2a92365cd3)
Comment 9 GCC Commits 2020-12-02 12:21:16 UTC
The releases/gcc-9 branch has been updated by Richard Biener <rguenth@gcc.gnu.org>:

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

commit r9-9087-ga5fff78405c3bfea287434e7711c6f10a770cb0a
Author: Richard Biener <rguenther@suse.de>
Date:   Thu Jul 30 10:24:42 2020 +0200

    tree-optimization/96370 - make reassoc expr rewrite more robust
    
    In the face of the more complex tricks in reassoc with respect
    to negate processing it can happen that the expression rewrite
    is fooled to recurse on a leaf and pick up a bogus expression
    code.  The following patch makes the expression rewrite more
    robust in providing the expression code to it directly since
    it is the same for all operations in a chain.
    
    2020-07-30  Richard Biener  <rguenther@suse.de>
    
            PR tree-optimization/96370
            * tree-ssa-reassoc.c (rewrite_expr_tree): Add operation
            code parameter and use it instead of picking it up from
            the stmt that is being rewritten.
            (reassociate_bb): Pass down the operation code.
    
            * gcc.dg/pr96370.c: New testcase.
    
    (cherry picked from commit 2c558d2655cb22f472c83e8296b5cd2a92365cd3)
Comment 10 GCC Commits 2021-03-17 11:14:11 UTC
The releases/gcc-8 branch has been updated by Richard Biener <rguenth@gcc.gnu.org>:

https://gcc.gnu.org/g:0307275acc789491bcc33dc67948009ec7d9c51d

commit r8-10804-g0307275acc789491bcc33dc67948009ec7d9c51d
Author: Richard Biener <rguenther@suse.de>
Date:   Thu Jul 30 10:24:42 2020 +0200

    tree-optimization/96370 - make reassoc expr rewrite more robust
    
    In the face of the more complex tricks in reassoc with respect
    to negate processing it can happen that the expression rewrite
    is fooled to recurse on a leaf and pick up a bogus expression
    code.  The following patch makes the expression rewrite more
    robust in providing the expression code to it directly since
    it is the same for all operations in a chain.
    
    2020-07-30  Richard Biener  <rguenther@suse.de>
    
            PR tree-optimization/96370
            * tree-ssa-reassoc.c (rewrite_expr_tree): Add operation
            code parameter and use it instead of picking it up from
            the stmt that is being rewritten.
            (reassociate_bb): Pass down the operation code.
    
            * gcc.dg/pr96370.c: New testcase.
    
    (cherry picked from commit a5fff78405c3bfea287434e7711c6f10a770cb0a)
Comment 11 Richard Biener 2021-03-17 11:15:59 UTC
Fixed.