From: Richard Biener <rguenther@suse.de>
To: Jakub Jelinek <jakub@redhat.com>
Cc: gcc-patches@gcc.gnu.org
Subject: Re: [PATCH] phiopt, v2: Handle bool in two_value_replacement [PR796232]
Date: Sat, 05 Dec 2020 13:52:00 +0100 [thread overview]
Message-ID: <9156511A-B928-41C5-866B-40E1E47143E8@suse.de> (raw)
In-Reply-To: <20201205105922.GA3788@tucnak>
On December 5, 2020 11:59:22 AM GMT+01:00, Jakub Jelinek <jakub@redhat.com> wrote:
>On Sat, Dec 05, 2020 at 11:22:24AM +0100, Richard Biener wrote:
>> >two_value_replacement and didn't restrict it to !early_p. Shall we
>> >instead
>> >do two_value_replacement only in late phiopt?
>>
>> Yeah, I guess that would make sense. I don't remember exactly but I
>saw
>> regressions with early doing if conversion besides min/max/abs
>detection.
>
>So that would be then following patch instead.
>Ok if it passes bootstrap/regtest?
Ok.
Richard.
>2020-12-05 Jakub Jelinek <jakub@redhat.com>
>
> PR tree-optimization/96232
> * tree-ssa-phiopt.c (two_value_replacement): Optimize even boolean lhs
> cases as long as arg0 has wider precision and conditional_replacement
> doesn't handle that case.
> (tree_ssa_phiopt_worker): Don't call two_value_replacement during
> early phiopt.
>
> * gcc.dg/tree-ssa/pr96232-2.c: New test.
>
>--- gcc/tree-ssa-phiopt.c.jj 2020-12-05 11:37:39.216203475 +0100
>+++ gcc/tree-ssa-phiopt.c 2020-12-05 11:51:57.497472991 +0100
>@@ -337,7 +337,7 @@ tree_ssa_phiopt_worker (bool do_store_el
> }
>
> /* Do the replacement of conditional if it can be done. */
>- if (two_value_replacement (bb, bb1, e2, phi, arg0, arg1))
>+ if (!early_p && two_value_replacement (bb, bb1, e2, phi, arg0,
>arg1))
> cfgchanged = true;
> else if (!early_p
> && conditional_replacement (bb, bb1, e1, e2, phi,
>@@ -635,7 +635,6 @@ two_value_replacement (basic_block cond_
>
> if (TREE_CODE (lhs) != SSA_NAME
> || !INTEGRAL_TYPE_P (TREE_TYPE (lhs))
>- || TREE_CODE (TREE_TYPE (lhs)) == BOOLEAN_TYPE
> || TREE_CODE (rhs) != INTEGER_CST)
> return false;
>
>@@ -648,9 +647,25 @@ two_value_replacement (basic_block cond_
> return false;
> }
>
>+ /* Defer boolean x ? 0 : {1,-1} or x ? {1,-1} : 0 to
>+ conditional_replacement. */
>+ if (TREE_CODE (TREE_TYPE (lhs)) == BOOLEAN_TYPE
>+ && (integer_zerop (arg0)
>+ || integer_zerop (arg1)
>+ || TREE_CODE (TREE_TYPE (arg0)) == BOOLEAN_TYPE
>+ || (TYPE_PRECISION (TREE_TYPE (arg0))
>+ <= TYPE_PRECISION (TREE_TYPE (lhs)))))
>+ return false;
>+
> wide_int min, max;
>- if (get_range_info (lhs, &min, &max) != VR_RANGE
>- || min + 1 != max
>+ if (TREE_CODE (TREE_TYPE (lhs)) == BOOLEAN_TYPE)
>+ {
>+ min = wi::to_wide (boolean_false_node);
>+ max = wi::to_wide (boolean_true_node);
>+ }
>+ else if (get_range_info (lhs, &min, &max) != VR_RANGE)
>+ return false;
>+ if (min + 1 != max
> || (wi::to_wide (rhs) != min
> && wi::to_wide (rhs) != max))
> return false;
>--- gcc/testsuite/gcc.dg/tree-ssa/pr96232-2.c.jj 2020-12-05
>11:51:01.891103252 +0100
>+++ gcc/testsuite/gcc.dg/tree-ssa/pr96232-2.c 2020-12-05
>11:51:01.891103252 +0100
>@@ -0,0 +1,18 @@
>+/* PR tree-optimization/96232 */
>+/* { dg-do compile } */
>+/* { dg-options "-O2 -fdump-tree-optimized" } */
>+/* { dg-final { scan-tree-dump " 38 - " "optimized" } } */
>+/* { dg-final { scan-tree-dump " \\+ 97;" "optimized" } } */
>+/* { dg-final { scan-tree-dump-not "PHI <" "optimized" } } */
>+
>+int
>+foo (_Bool x)
>+{
>+ return x ? 37 : 38;
>+}
>+
>+int
>+bar (_Bool x)
>+{
>+ return x ? 98 : 97;
>+}
>
>
> Jakub
prev parent reply other threads:[~2020-12-05 12:52 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-12-05 9:14 [PATCH] phiopt: " Jakub Jelinek
2020-12-05 10:22 ` Richard Biener
2020-12-05 10:59 ` [PATCH] phiopt, v2: " Jakub Jelinek
2020-12-05 12:52 ` Richard Biener [this message]
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=9156511A-B928-41C5-866B-40E1E47143E8@suse.de \
--to=rguenther@suse.de \
--cc=gcc-patches@gcc.gnu.org \
--cc=jakub@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).