gimple-fold.c (gimple_fold_stmt_to_constant_1): For ternary ops with an embedded...
authorRichard Guenther <rguenther@suse.de>
Wed, 5 Oct 2011 10:54:14 +0000 (10:54 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Wed, 5 Oct 2011 10:54:14 +0000 (10:54 +0000)
2011-10-05  Richard Guenther  <rguenther@suse.de>

* gimple-fold.c (gimple_fold_stmt_to_constant_1): For
ternary ops with an embedded expression valueize and fold
that as well.
* tree-ssa-sccvn.c (try_to_simplify): Also allow SSA name
results from gimple_fold_stmt_to_constant_1.

From-SVN: r179543

gcc/ChangeLog
gcc/gimple-fold.c
gcc/tree-ssa-sccvn.c

index a50a4f4430761d1372349cdc9c84a5eb6b0bb445..da53b3869759fdfc16a4a0198719be559fa162f2 100644 (file)
@@ -1,3 +1,11 @@
+2011-10-05  Richard Guenther  <rguenther@suse.de>
+
+       * gimple-fold.c (gimple_fold_stmt_to_constant_1): For
+       ternary ops with an embedded expression valueize and fold
+       that as well.
+       * tree-ssa-sccvn.c (try_to_simplify): Also allow SSA name
+       results from gimple_fold_stmt_to_constant_1.
+
 2011-10-05  Nick Clifton  <nickc@redhat.com>
 
        * config/rx/rx.md (tablejump): Add missing label.
index 179535ef56677711e2432e3fd2172cc78604ab36..fcfbcc8f5b332a00e9251cfaaa64ccdca786f12b 100644 (file)
@@ -2569,6 +2569,19 @@ gimple_fold_stmt_to_constant_1 (gimple stmt, tree (*valueize) (tree))
               tree op1 = (*valueize) (gimple_assign_rhs2 (stmt));
               tree op2 = (*valueize) (gimple_assign_rhs3 (stmt));
 
+             /* Fold embedded expressions in ternary codes.  */
+             if ((subcode == COND_EXPR
+                  || subcode == VEC_COND_EXPR)
+                 && COMPARISON_CLASS_P (op0))
+               {
+                 tree op00 = (*valueize) (TREE_OPERAND (op0, 0));
+                 tree op01 = (*valueize) (TREE_OPERAND (op0, 1));
+                 tree tem = fold_binary_loc (loc, TREE_CODE (op0),
+                                             TREE_TYPE (op0), op00, op01);
+                 if (tem)
+                   op0 = tem;
+               }
+
               return fold_ternary_loc (loc, subcode,
                                       gimple_expr_type (stmt), op0, op1, op2);
             }
index 003804b3ca88062f0cd7174945141e709393f779..208c272d37169384232257668c7fcd7819cf8cbc 100644 (file)
@@ -2967,27 +2967,29 @@ simplify_unary_expression (gimple stmt)
 static tree
 try_to_simplify (gimple stmt)
 {
+  enum tree_code code = gimple_assign_rhs_code (stmt);
   tree tem;
 
   /* For stores we can end up simplifying a SSA_NAME rhs.  Just return
      in this case, there is no point in doing extra work.  */
-  if (gimple_assign_copy_p (stmt)
-      && TREE_CODE (gimple_assign_rhs1 (stmt)) == SSA_NAME)
+  if (code == SSA_NAME)
     return NULL_TREE;
 
   /* First try constant folding based on our current lattice.  */
-  tem = gimple_fold_stmt_to_constant (stmt, vn_valueize);
-  if (tem)
+  tem = gimple_fold_stmt_to_constant_1 (stmt, vn_valueize);
+  if (tem
+      && (TREE_CODE (tem) == SSA_NAME
+         || is_gimple_min_invariant (tem)))
     return tem;
 
   /* If that didn't work try combining multiple statements.  */
-  switch (TREE_CODE_CLASS (gimple_assign_rhs_code (stmt)))
+  switch (TREE_CODE_CLASS (code))
     {
     case tcc_reference:
-      /* Fallthrough for some codes that can operate on registers.  */
-      if (!(TREE_CODE (gimple_assign_rhs1 (stmt)) == REALPART_EXPR
-           || TREE_CODE (gimple_assign_rhs1 (stmt)) == IMAGPART_EXPR
-           || TREE_CODE (gimple_assign_rhs1 (stmt)) == VIEW_CONVERT_EXPR))
+      /* Fallthrough for some unary codes that can operate on registers.  */
+      if (!(code == REALPART_EXPR
+           || code == IMAGPART_EXPR
+           || code == VIEW_CONVERT_EXPR))
        break;
       /* We could do a little more with unary ops, if they expand
         into binary ops, but it's debatable whether it is worth it. */