Comments
Patch
@@ -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
@@ -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
new file mode 100644
@@ -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" } } */
+
@@ -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" } } */
@@ -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:
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.