public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Richard Biener <rguenther@suse.de>
To: Jakub Jelinek <jakub@redhat.com>
Cc: Jonathan Wakely <jwakely@redhat.com>,
	Jason Merrill <jason@redhat.com>,
	 gcc-patches@gcc.gnu.org
Subject: Re: [PATCH] phiopt, v2: Optimize (x <=> y) cmp z [PR94589]
Date: Wed, 5 May 2021 16:17:37 +0200 (CEST)	[thread overview]
Message-ID: <nycvar.YFH.7.76.2105051617260.9200@zhemvz.fhfr.qr> (raw)
In-Reply-To: <20210505131812.GQ1179226@tucnak>

On Wed, 5 May 2021, Jakub Jelinek wrote:

> On Wed, May 05, 2021 at 01:39:32PM +0200, Richard Biener wrote:
> > Can you in the above IL snippets mark COND_BB and MIDDLE_BB?
> ...
> 
> Thanks.
> Here is an updated patch (attached) and interdiff from previous patch.
> Ok for trunk if it passes bootstrap/regtest?

OK.

Thanks,
Richard.

> --- gcc/tree-ssa-phiopt.c	2021-05-03 17:49:54.233300624 +0200
> +++ gcc/tree-ssa-phiopt.c	2021-05-05 15:06:23.253189139 +0200
> @@ -65,7 +65,7 @@
>  static bool xor_replacement (basic_block, basic_block,
>  			     edge, edge, gimple *, tree, tree);
>  static bool spaceship_replacement (basic_block, basic_block,
> -				   edge, edge, gimple *, tree, tree);
> +				   edge, edge, gphi *, tree, tree);
>  static bool cond_removal_in_popcount_clz_ctz_pattern (basic_block, basic_block,
>  						      edge, edge, gimple *,
>  						      tree, tree);
> @@ -1840,53 +1840,53 @@
>  
>  /* Attempt to optimize (x <=> y) cmp 0 and similar comparisons.
>     For strong ordering <=> try to match something like:
> -    <bb 2> :
> +    <bb 2> :  // cond3_bb (== cond2_bb)
>      if (x_4(D) != y_5(D))
>        goto <bb 3>; [INV]
>      else
>        goto <bb 6>; [INV]
>  
> -    <bb 3> :
> +    <bb 3> :  // cond_bb
>      if (x_4(D) < y_5(D))
>        goto <bb 6>; [INV]
>      else
>        goto <bb 4>; [INV]
>  
> -    <bb 4> :
> +    <bb 4> :  // middle_bb
>  
> -    <bb 6> :
> +    <bb 6> :  // phi_bb
>      # iftmp.0_2 = PHI <1(4), 0(2), -1(3)>
>      _1 = iftmp.0_2 == 0;
>  
>     and for partial ordering <=> something like:
>  
> -    <bb 2> :
> +    <bb 2> :  // cond3_bb
>      if (a_3(D) == b_5(D))
>        goto <bb 6>; [50.00%]
>      else
>        goto <bb 3>; [50.00%]
>  
> -    <bb 3> [local count: 536870913]:
> +    <bb 3> [local count: 536870913]:  // cond2_bb
>      if (a_3(D) < b_5(D))
>        goto <bb 6>; [50.00%]
>      else
>        goto <bb 4>; [50.00%]
>  
> -    <bb 4> [local count: 268435456]:
> +    <bb 4> [local count: 268435456]:  // cond_bb
>      if (a_3(D) > b_5(D))
>        goto <bb 6>; [50.00%]
>      else
>        goto <bb 5>; [50.00%]
>  
> -    <bb 5> [local count: 134217728]:
> +    <bb 5> [local count: 134217728]:  // middle_bb
>  
> -    <bb 6> [local count: 1073741824]:
> +    <bb 6> [local count: 1073741824]:  // phi_bb
>      # SR.27_4 = PHI <0(2), -1(3), 1(4), 2(5)>
>      _2 = SR.27_4 > 0;  */
>  
>  static bool
>  spaceship_replacement (basic_block cond_bb, basic_block middle_bb,
> -		       edge e0, edge e1, gimple *phi,
> +		       edge e0, edge e1, gphi *phi,
>  		       tree arg0, tree arg1)
>  {
>    if (!INTEGRAL_TYPE_P (TREE_TYPE (PHI_RESULT (phi)))
> @@ -1897,6 +1897,11 @@
>        || !IN_RANGE (tree_to_shwi (arg1), -1, 2))
>      return false;
>  
> +  basic_block phi_bb = gimple_bb (phi);
> +  gcc_assert (phi_bb == e0->dest && phi_bb == e1->dest);
> +  if (!IN_RANGE (EDGE_COUNT (phi_bb->preds), 3, 4))
> +    return false;
> +
>    use_operand_p use_p;
>    gimple *use_stmt;
>    if (SSA_NAME_OCCURS_IN_ABNORMAL_PHI (PHI_RESULT (phi)))
> @@ -1953,11 +1958,6 @@
>    if (!empty_block_p (middle_bb))
>      return false;
>  
> -  basic_block phi_bb = gimple_bb (phi);
> -  gcc_assert (phi_bb == e0->dest && phi_bb == e1->dest);
> -  if (!IN_RANGE (EDGE_COUNT (phi_bb->preds), 3, 4))
> -    return false;
> -
>    gcond *cond1 = as_a <gcond *> (last_stmt (cond_bb));
>    enum tree_code cmp1 = gimple_cond_code (cond1);
>    if (cmp1 != LT_EXPR && cmp1 != GT_EXPR)
> @@ -1965,7 +1965,7 @@
>    tree lhs1 = gimple_cond_lhs (cond1);
>    tree rhs1 = gimple_cond_rhs (cond1);
>    /* The optimization may be unsafe due to NaNs.  */
> -  if (HONOR_NANS (TREE_TYPE (lhs1)) || HONOR_SIGNED_ZEROS (TREE_TYPE (lhs1)))
> +  if (HONOR_NANS (TREE_TYPE (lhs1)))
>      return false;
>    if (TREE_CODE (lhs1) == SSA_NAME && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (lhs1))
>      return false;
> @@ -2180,11 +2180,6 @@
>        gimple_assign_set_rhs1 (use_stmt, cond);
>      }
>    update_stmt (use_stmt);
> -  if (cmp3 == EQ_EXPR)
> -    gimple_cond_make_true (as_a <gcond *> (cond3));
> -  else
> -    gimple_cond_make_false (as_a <gcond *> (cond3));
> -  update_stmt (cond3);
>  
>    if (MAY_HAVE_DEBUG_BIND_STMTS)
>      {
> @@ -2201,6 +2196,13 @@
>  
>        if (has_debug_uses)
>  	{
> +	  /* If there are debug uses, emit something like:
> +	     # DEBUG D#1 => i_2(D) > j_3(D) ? 1 : -1
> +	     # DEBUG D#2 => i_2(D) == j_3(D) ? 0 : D#1
> +	     where > stands for the comparison that yielded 1
> +	     and replace debug uses of phi result with that D#2.
> +	     Ignore the value of 2, because if NaNs aren't expected,
> +	     all floating point numbers should be comparable.  */
>  	  gimple_stmt_iterator gsi = gsi_after_labels (gimple_bb (phi));
>  	  tree type = TREE_TYPE (PHI_RESULT (phi));
>  	  tree temp1 = make_node (DEBUG_EXPR_DECL);
> @@ -2224,6 +2226,9 @@
>  	}
>      }
>  
> +  gimple_stmt_iterator psi = gsi_for_stmt (phi);
> +  remove_phi_node (&psi, true);
> +
>    return true;
>  }
>  
> 
> 
> 	Jakub
> 

-- 
Richard Biener <rguenther@suse.de>
SUSE Software Solutions Germany GmbH, Maxfeldstrasse 5, 90409 Nuernberg,
Germany; GF: Felix Imendörffer; HRB 36809 (AG Nuernberg)

  reply	other threads:[~2021-05-05 14:17 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-04  7:44 [PATCH] phiopt: " Jakub Jelinek
2021-05-04  9:42 ` Jonathan Wakely
2021-05-04  9:56   ` Jakub Jelinek
2021-05-05 11:39 ` Richard Biener
2021-05-05 13:18   ` [PATCH] phiopt, v2: " Jakub Jelinek
2021-05-05 14:17     ` Richard Biener [this message]
2021-05-05 11:45 ` [PATCH] phiopt: " Marc Glisse
2021-05-05 16:52   ` Jakub Jelinek
2021-05-06 10:22     ` Jakub Jelinek
2021-05-06 19:42       ` Marc Glisse
2021-05-11  7:34         ` [PATCH] match.pd: Optimize (x & y) == x into (x & ~y) == 0 [PR94589] Jakub Jelinek
2021-05-11  8:11           ` Marc Glisse
2021-05-11  8:20           ` Richard Biener
2021-05-14 17:26         ` [PATCH] phiopt: Optimize (x <=> y) cmp z [PR94589] Jakub Jelinek
2021-05-15 10:09           ` Marc Glisse
2021-05-05 15:45 ` Martin Sebor

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=nycvar.YFH.7.76.2105051617260.9200@zhemvz.fhfr.qr \
    --to=rguenther@suse.de \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jakub@redhat.com \
    --cc=jason@redhat.com \
    --cc=jwakely@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).