[#7/7] handle TRUTH_ANDIF cond exprs in ifcombine_replace_cond (was: Re: [PATCH] fold fold_truth_andor field merging into ifcombine)

Message ID or7c9wv1i6.fsf_-_@lxoliva.fsfla.org
State Committed
Commit 13cf22eb557eb5e3d796822247d8d4957bdb25da
Headers
Series [#1/7] allow vuses in ifcombine blocks (was: Re: [PATCH] fold fold_truth_andor field merging into ifcombine) |

Commit Message

Alexandre Oliva Oct. 25, 2024, 11:57 a.m. UTC
  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 |   11 +++++++++++
 1 file changed, 11 insertions(+)
  

Comments

Jeff Law Oct. 31, 2024, 3:30 p.m. UTC | #1
On 10/25/24 5:57 AM, Alexandre Oliva wrote:
> 
> 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.
OK.  A bit surprised to see those codes showing up here, but if they do, 
we might as well handle them sensibly.

jeff
  
Alexandre Oliva Nov. 2, 2024, 5:52 a.m. UTC | #2
On Oct 31, 2024, Jeff Law <jeffreyalaw@gmail.com> wrote:

> On 10/25/24 5:57 AM, Alexandre Oliva wrote:
>> 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.

> OK.  A bit surprised to see those codes showing up here, but if they
> do, we might as well handle them sensibly.

As stated in the cover letter (#0/7), it doesn't show up yet, but it
will once fold_truth_andor is plugged into ifcombine.
  

Patch

diff --git a/gcc/tree-ssa-ifcombine.cc b/gcc/tree-ssa-ifcombine.cc
index 817c95b20252e..6194e92bd3816 100644
--- a/gcc/tree-ssa-ifcombine.cc
+++ b/gcc/tree-ssa-ifcombine.cc
@@ -518,6 +518,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;