re PR tree-optimization/52631 (VN does not use simplified expression for lookup)
authorJeff Law <law@gcc.gnu.org>
Sun, 20 Jan 2013 05:00:56 +0000 (22:00 -0700)
committerJeff Law <law@gcc.gnu.org>
Sun, 20 Jan 2013 05:00:56 +0000 (22:00 -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.

From-SVN: r195318

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/tree-ssa/pr52631.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-9.c
gcc/tree-ssa-sccvn.c

index 2c01942622fab3432eef6c19dba5e2554aabc6e3..528afa12c3f4f5b889881ec4277358836be2d039 100644 (file)
@@ -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
index d6a8f70619d2682ab6097d5804ab701c1296e6e5..0d502962e031959ff0cf55cc2629094b0a6bb9c3 100644 (file)
@@ -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 (file)
index 0000000..c0d650b
--- /dev/null
@@ -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" } } */
+
index 57c6d4b5be7f7aa3d6d6dd7ccad4c569df63a17a..d3986f5ba17723e59a4effb6016a0d3e35003918 100644 (file)
@@ -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" } } */
index 57940357a6b9eb1afd388aa173681ab8e88618f4..81a07aefb4fc72cfe6c47df160f5403c944b63d1 100644 (file)
@@ -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: