[gcc(refs/users/aoliva/heads/testme)] fold truth-and only in ifcombine

Alexandre Oliva aoliva@gcc.gnu.org
Thu Sep 19 06:32:22 GMT 2024


https://gcc.gnu.org/g:15a55a94711d51d95fb6b5ba763903d75e85324e

commit 15a55a94711d51d95fb6b5ba763903d75e85324e
Author: Alexandre Oliva <oliva@gnu.org>
Date:   Tue Sep 17 20:15:35 2024 -0300

    fold truth-and only in ifcombine

Diff:
---
 gcc/gimple-fold.cc        |  2 ++
 gcc/tree-ssa-ifcombine.cc | 24 +++++++++++++++++++++---
 2 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/gcc/gimple-fold.cc b/gcc/gimple-fold.cc
index 85a0ec028030..5b7d83edbea9 100644
--- a/gcc/gimple-fold.cc
+++ b/gcc/gimple-fold.cc
@@ -8738,12 +8738,14 @@ maybe_fold_and_comparisons (tree type,
 						     op2b, outer_cond_bb))
     return t;
 
+#if 0
   if (tree t = fold_truth_andor_maybe_separate (UNKNOWN_LOCATION,
 						TRUTH_ANDIF_EXPR, type,
 						code2, op2a, op2b,
 						code1, op1a, op1b,
 						NULL))
     return t;
+#endif
 
   return NULL_TREE;
 }
diff --git a/gcc/tree-ssa-ifcombine.cc b/gcc/tree-ssa-ifcombine.cc
index 79a4bdd363b9..61480e5fa894 100644
--- a/gcc/tree-ssa-ifcombine.cc
+++ b/gcc/tree-ssa-ifcombine.cc
@@ -399,6 +399,14 @@ update_profile_after_ifcombine (basic_block inner_cond_bb,
   outer2->probability = profile_probability::never ();
 }
 
+/* FIXME: move to a header file.  */
+extern tree
+fold_truth_andor_maybe_separate (location_t loc,
+				 enum tree_code code, tree truth_type,
+				 enum tree_code lcode, tree ll_arg, tree lr_arg,
+				 enum tree_code rcode, tree rl_arg, tree rr_arg,
+				 tree *separatep);
+
 /* If-convert on a and pattern with a common else block.  The inner
    if is specified by its INNER_COND_BB, the outer by OUTER_COND_BB.
    inner_inv, outer_inv and result_inv indicate whether the conditions
@@ -576,7 +584,7 @@ ifcombine_ifandif (basic_block inner_cond_bb, bool inner_inv,
   else if (TREE_CODE_CLASS (gimple_cond_code (inner_cond)) == tcc_comparison
 	   && TREE_CODE_CLASS (gimple_cond_code (outer_cond)) == tcc_comparison)
     {
-      tree t;
+      tree t, ts = NULL_TREE;
       enum tree_code inner_cond_code = gimple_cond_code (inner_cond);
       enum tree_code outer_cond_code = gimple_cond_code (outer_cond);
 
@@ -599,7 +607,17 @@ ifcombine_ifandif (basic_block inner_cond_bb, bool inner_inv,
 					    outer_cond_code,
 					    gimple_cond_lhs (outer_cond),
 					    gimple_cond_rhs (outer_cond),
-					    gimple_bb (outer_cond))))
+					    gimple_bb (outer_cond)))
+	  && !(t = ts = (fold_truth_andor_maybe_separate
+			 (UNKNOWN_LOCATION, TRUTH_ANDIF_EXPR,
+			  boolean_type_node,
+			  outer_cond_code,
+			  gimple_cond_lhs (outer_cond),
+			  gimple_cond_rhs (outer_cond),
+			  inner_cond_code,
+			  gimple_cond_lhs (inner_cond),
+			  gimple_cond_rhs (inner_cond),
+			  NULL))))
 	{
 	  {
 	  tree t1, t2;
@@ -636,7 +654,7 @@ ifcombine_ifandif (basic_block inner_cond_bb, bool inner_inv,
 					  NULL, true, GSI_SAME_STMT);
         }
       /* ??? Fold should avoid this.  */
-      else if (!is_gimple_condexpr_for_cond (t))
+      else if (ts && !is_gimple_condexpr_for_cond (t))
 	goto gimplify_after_fold;
       if (result_inv)
 	t = fold_build1 (TRUTH_NOT_EXPR, TREE_TYPE (t), t);


More information about the Gcc-cvs mailing list