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.
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.
> > Thanks to cvise for reducing the code quickly. Glad to hear you used cvise!
Started with r7-950-g8a85cee26eabf5cf.
More "complete" testcase: void c(_Decimal128); void a(_Decimal128 b) { c(-b * b); }
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.
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.
Fixed on trunk sofar.
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)
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)
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)
Fixed.