]> gcc.gnu.org Git - gcc.git/commitdiff
tree-optimization/96370 - make reassoc expr rewrite more robust
authorRichard Biener <rguenther@suse.de>
Thu, 30 Jul 2020 08:24:42 +0000 (10:24 +0200)
committerRichard Biener <rguenther@suse.de>
Fri, 11 Sep 2020 12:10:29 +0000 (14:10 +0200)
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)

gcc/testsuite/gcc.dg/pr96370.c [new file with mode: 0644]
gcc/tree-ssa-reassoc.c

diff --git a/gcc/testsuite/gcc.dg/pr96370.c b/gcc/testsuite/gcc.dg/pr96370.c
new file mode 100644 (file)
index 0000000..b939b21
--- /dev/null
@@ -0,0 +1,8 @@
+/* { dg-do compile { target dfp } } */
+/* { dg-options "-O2 -ffast-math" } */
+
+void c(_Decimal128);
+void a(_Decimal128 b)
+{
+  c(-b * b);
+}
index ec1c033a2cff990a6a4a67f74dfc2147e8eafecb..c45b9e95c557459429a7c7282dc968795dd58029 100644 (file)
@@ -4844,7 +4844,7 @@ insert_stmt_before_use (gimple *stmt, gimple *stmt_to_insert)
    recursive invocations.  */
 
 static tree
-rewrite_expr_tree (gimple *stmt, unsigned int opindex,
+rewrite_expr_tree (gimple *stmt, enum tree_code rhs_code, unsigned int opindex,
                   vec<operand_entry *> ops, bool changed, bool next_changed)
 {
   tree rhs1 = gimple_assign_rhs1 (stmt);
@@ -4891,7 +4891,7 @@ rewrite_expr_tree (gimple *stmt, unsigned int opindex,
                = find_insert_point (stmt, oe1->op, oe2->op);
              lhs = make_ssa_name (TREE_TYPE (lhs));
              stmt
-               = gimple_build_assign (lhs, gimple_assign_rhs_code (stmt),
+               = gimple_build_assign (lhs, rhs_code,
                                       oe1->op, oe2->op);
              gimple_set_uid (stmt, uid);
              gimple_set_visited (stmt, true);
@@ -4935,7 +4935,7 @@ rewrite_expr_tree (gimple *stmt, unsigned int opindex,
   /* 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,
+    = rewrite_expr_tree (SSA_NAME_DEF_STMT (rhs1), rhs_code, opindex + 1, ops,
                         changed || oe->op != rhs2 || next_changed,
                         false);
 
@@ -4961,7 +4961,7 @@ rewrite_expr_tree (gimple *stmt, unsigned int opindex,
          gimple *insert_point = find_insert_point (stmt, new_rhs1, oe->op);
 
          lhs = make_ssa_name (TREE_TYPE (lhs));
-         stmt = gimple_build_assign (lhs, gimple_assign_rhs_code (stmt),
+         stmt = gimple_build_assign (lhs, rhs_code,
                                      new_rhs1, oe->op);
          gimple_set_uid (stmt, uid);
          gimple_set_visited (stmt, true);
@@ -6408,7 +6408,7 @@ reassociate_bb (basic_block bb)
                       if (len >= 3)
                         swap_ops_for_binary_stmt (ops, len - 3, stmt);
 
-                     new_lhs = rewrite_expr_tree (stmt, 0, ops,
+                     new_lhs = rewrite_expr_tree (stmt, rhs_code, 0, ops,
                                                   powi_result != NULL
                                                   || negate_result,
                                                   len != orig_len);
This page took 0.082682 seconds and 5 git commands to generate.