[gcc r8-10805] tree-optimization/96579 - another special-operands fix in reassoc

Richard Biener rguenth@gcc.gnu.org
Wed Mar 17 11:14:15 GMT 2021


https://gcc.gnu.org/g:19b7dd1caf953f8b79b16c6fc0439dba2a598b1f

commit r8-10805-g19b7dd1caf953f8b79b16c6fc0439dba2a598b1f
Author: Richard Biener <rguenther@suse.de>
Date:   Thu Aug 27 10:02:22 2020 +0200

    tree-optimization/96579 - another special-operands fix in reassoc
    
    This makes sure to put special-ops expanded rhs left where
    expression rewrite expects it.
    
    2020-08-27  Richard Biener  <rguenther@suse.de>
    
            PR tree-optimization/96579
            * tree-ssa-reassoc.c (linearize_expr_tree): If we expand
            rhs via special ops make sure to swap operands.
    
            * gcc.dg/pr96579.c: New testcase.
    
    (cherry picked from commit 92b6627874cc924eeed9084a09f09504e20b5387)

Diff:
---
 gcc/testsuite/gcc.dg/pr96579.c |  4 ++++
 gcc/tree-ssa-reassoc.c         | 13 +++++++++++--
 2 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/gcc/testsuite/gcc.dg/pr96579.c b/gcc/testsuite/gcc.dg/pr96579.c
new file mode 100644
index 00000000000..982f8ac17a5
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr96579.c
@@ -0,0 +1,4 @@
+/* { dg-do compile { target dfp } } */
+/* { dg-options "-O -fno-tree-forwprop -ffast-math -fno-tree-vrp" } */
+
+#include "pr96370.c"
diff --git a/gcc/tree-ssa-reassoc.c b/gcc/tree-ssa-reassoc.c
index 4728c76a73d..a7580c5c7b5 100644
--- a/gcc/tree-ssa-reassoc.c
+++ b/gcc/tree-ssa-reassoc.c
@@ -5119,13 +5119,20 @@ linearize_expr_tree (vec<operand_entry *> *ops, gimple *stmt,
 
       if (!binrhsisreassoc)
 	{
-	  if (!try_special_add_to_ops (ops, rhscode, binrhs, binrhsdef))
+	  bool swap = false;
+	  if (try_special_add_to_ops (ops, rhscode, binrhs, binrhsdef))
+	    /* If we add ops for the rhs we expect to be able to recurse
+	       to it via the lhs during expression rewrite so swap
+	       operands.  */
+	    swap = true;
+	  else
 	    add_to_ops_vec (ops, binrhs);
 
 	  if (!try_special_add_to_ops (ops, rhscode, binlhs, binlhsdef))
 	    add_to_ops_vec (ops, binlhs);
 
-	  return;
+	  if (!swap)
+	    return;
 	}
 
       if (dump_file && (dump_flags & TDF_DETAILS))
@@ -5144,6 +5151,8 @@ linearize_expr_tree (vec<operand_entry *> *ops, gimple *stmt,
 	  fprintf (dump_file, " is now ");
 	  print_gimple_stmt (dump_file, stmt, 0);
 	}
+      if (!binrhsisreassoc)
+	return;
 
       /* We want to make it so the lhs is always the reassociative op,
 	 so swap.  */


More information about the Gcc-cvs mailing list