diff mbox

PR 52631

Message ID 50FB79FD.3070605@redhat.com
State New
Headers show

Commit Message

Jeff Law Jan. 20, 2013, 5 a.m. UTC
PR 52631 is a missed-optimization regression where we fail to lookup a 
simplified expression when value numbering the ssa graph to see if the 
simplified expression already has a value number.

Andrew Pinski had a patch that was 99% complete in the PR; Richard 
Biener suggested a relatively minor change.  Specifically instead of 
using valid_gimple_rhs_p to explicitly check for the valid codes.  I've 
made that trivial change, added Andrew's sample code to the testsuite 
and updated the expected output from one test that we optimize better 
during FRE.

Bootstrapped and regression tested on x86_64-linux-gnu.

Applied to the trunk.
commit cb8cc8bfd2be2c7cd0b3906e28f0c5557b62379a
Author: Jeff Law <law@redhat.com>
Date:   Sat Jan 19 21:51:27 2013 -0700

            PR tree-optimization/52631
            * tree-ssa-sccvn (visit_use): Before looking up the original
            statement, try looking up the simplified expression.
    
            PR tree-optimization/52631
            * tree-ssa/pr52631.c: New test.
            * tree-ssa/ssa-fre-9: Update expected output.
diff mbox

Patch

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 2c01942..528afa1 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,9 @@ 
+2013-01-19  Andrew Pinski  <apinski@cavium.com>
+
+	PR tree-optimization/52631
+	* tree-ssa-sccvn (visit_use): Before looking up the original
+	statement, try looking up the simplified expression.
+
 2013-01-19  Anthony Green  <green@moxielogic.com>
 
 	* config/moxie/moxie.c (moxie_expand_prologue): Set
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index d6a8f70..0d50296 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,9 @@ 
+2013-01-19  Jeff Law  <law@redhat.com>
+
+	PR tree-optimization/52631
+	* tree-ssa/pr52631.c: New test.
+	* tree-ssa/ssa-fre-9: Update expected output.
+
 2013-01-19  Anthony Green  <green@moxielogic.com>
 
 	* gcc.dg/tree-ssa/asm-2.c (REGISTER): Pick an appropriate register
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr52631.c b/gcc/testsuite/gcc.dg/tree-ssa/pr52631.c
new file mode 100644
index 0000000..c0d650b
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/pr52631.c
@@ -0,0 +1,14 @@ 
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-fre1-details" } */
+
+unsigned f(unsigned a)
+{
+  unsigned b = a >> 31;
+  return b&1;
+}
+
+/* We want to verify that we replace the b & 1 with b.  */
+/* { dg-final { scan-tree-dump-times "Replaced b_\[0-9\]+ & 1 with b_\[0-9\]+ in" 1 "fre1"} } */
+ 
+/* { dg-final { cleanup-tree-dump "fre1" } } */
+
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-9.c b/gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-9.c
index 57c6d4b..d3986f5 100644
--- a/gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-9.c
+++ b/gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-9.c
@@ -23,6 +23,6 @@  void __frame_state_for1 (volatile char *state_in)
     }
 }
 
-/* { dg-final { scan-tree-dump-times "Eliminated: 1" 2 "fre1" } } */
+/* { dg-final { scan-tree-dump-times "Eliminated: 2" 2 "fre1" } } */
 /* { dg-final { scan-tree-dump-times "Insertions: 1" 2 "fre1" } } */
 /* { dg-final { cleanup-tree-dump "fre1" } } */
diff --git a/gcc/tree-ssa-sccvn.c b/gcc/tree-ssa-sccvn.c
index 5794035..81a07ae 100644
--- a/gcc/tree-ssa-sccvn.c
+++ b/gcc/tree-ssa-sccvn.c
@@ -3422,6 +3422,28 @@  visit_use (tree use)
 		}
 	      else
 		{
+		  /* First try to lookup the simplified expression.  */
+		  if (simplified)
+		    {
+		      enum gimple_rhs_class rhs_class;
+
+
+		      rhs_class = get_gimple_rhs_class (TREE_CODE (simplified));
+		      if ((rhs_class == GIMPLE_UNARY_RHS
+			   || rhs_class == GIMPLE_BINARY_RHS
+			   || rhs_class == GIMPLE_TERNARY_RHS)
+			  && valid_gimple_rhs_p (simplified))
+			{
+			  tree result = vn_nary_op_lookup (simplified, NULL);
+			  if (result)
+			    {
+			      changed = set_ssa_val_to (lhs, result);
+			      goto done;
+			    }
+			}
+		    }
+
+		  /* Otherwise visit the original statement.  */
 		  switch (vn_get_stmt_kind (stmt))
 		    {
 		    case VN_NARY: