]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
handle TRUTH_ANDIF cond exprs in ifcombine_replace_cond
authorAlexandre Oliva <oliva@adacore.com>
Thu, 7 Nov 2024 05:47:46 +0000 (02:47 -0300)
committerAlexandre Oliva <oliva@gnu.org>
Thu, 7 Nov 2024 05:47:46 +0000 (02:47 -0300)
The upcoming move of fold_truth_andor to ifcombine brings with it the
possibility of TRUTH_ANDIF cond exprs.  Handle them by splitting the
cond so as to best use both BB insertion points, but only if they're
contiguous.

for  gcc/ChangeLog

* tree-ssa-ifcombine.c (ifcombine_replace_cond): Support
TRUTH_ANDIF cond exprs.

gcc/tree-ssa-ifcombine.cc

index 158f2a645020345f0221a89d7b944a0551e2ce7c..d52510e3c3fbf383cbfa4138f2c9e1b335269bae 100644 (file)
@@ -519,6 +519,17 @@ ifcombine_replace_cond (gcond *inner_cond, bool inner_inv,
                        gcond *outer_cond, bool outer_inv,
                        tree cond, bool must_canon, tree cond2)
 {
+  /* Split cond into cond2 if they're contiguous.  ??? We might be able to
+     handle ORIF as well, inverting both conditions, but it's not clear that
+     this would be enough, and it never comes up.  */
+  if (!cond2
+      && TREE_CODE (cond) == TRUTH_ANDIF_EXPR
+      && single_pred (gimple_bb (inner_cond)) == gimple_bb (outer_cond))
+    {
+      cond2 = TREE_OPERAND (cond, 1);
+      cond = TREE_OPERAND (cond, 0);
+    }
+
   bool outer_p = cond2 || (single_pred (gimple_bb (inner_cond))
                           != gimple_bb (outer_cond));
   bool result_inv = outer_p ? outer_inv : inner_inv;