From: Richard Biener <rguenther@suse.de>
To: Jakub Jelinek <jakub@redhat.com>
Cc: gcc-patches@gcc.gnu.org
Subject: Re: [PATCH] match.pd: Improve conditional_replacement for x ? 0 : -1 [PR796232]
Date: Sat, 05 Dec 2020 13:51:35 +0100 [thread overview]
Message-ID: <C2453312-207C-4E3F-9A2D-1491E8731146@suse.de> (raw)
In-Reply-To: <20201205105746.GZ3788@tucnak>
On December 5, 2020 11:57:46 AM GMT+01:00, Jakub Jelinek <jakub@redhat.com> wrote:
>On Sat, Dec 05, 2020 at 11:20:11AM +0100, Richard Biener wrote:
>> >As mentioned in the PR, for boolean x we currently optimize
>> >in phiopt x ? 0 : -1 into -(int)!x but it can be optimized as
>> >(int) x - 1 which is one less operation both in GIMPLE and in x86
>> >assembly.
>> >
>> >Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
>> >
>> >And/or, shall we have a match.pd optimization to turn that -(type)!x
>> >for BOOLEAN_TYPE (or other 1 bit unsigned precision values) into
>> >(type) - 1.
>>
>> I think that would make sense. Does that then cover the phiopt case
>directly?
>
>That would be the following then. Seems it works for that case.
>Ok for trunk if it passes bootstrap/regtest?
Ok.
Richard.
>2020-12-05 Jakub Jelinek <jakub@redhat.com>
>
> PR tree-optimization/96232
> * match.pd (-(type)!A -> (type)A - 1): New optimization.
>
> * gcc.dg/tree-ssa/pr96232-1.c: New test.
>
>--- gcc/match.pd.jj 2020-12-02 11:20:24.765486816 +0100
>+++ gcc/match.pd 2020-12-05 11:46:00.554518927 +0100
>@@ -3812,6 +3812,16 @@ (define_operator_list COND_TERNARY
> (cnd (logical_inverted_value truth_valued_p@0) @1 @2)
> (cnd @0 @2 @1)))
>
>+/* -(type)!A -> (type)A - 1. */
>+(simplify
>+ (negate (convert?:s (logical_inverted_value:s @0)))
>+ (if (INTEGRAL_TYPE_P (type)
>+ && TREE_CODE (type) != BOOLEAN_TYPE
>+ && TYPE_PRECISION (type) > 1
>+ && TREE_CODE (@0) == SSA_NAME
>+ && ssa_name_has_boolean_range (@0))
>+ (plus (convert:type @0) { build_all_ones_cst (type); })))
>+
>/* A + (B vcmp C ? 1 : 0) -> A - (B vcmp C ? -1 : 0), since vector
>comparisons
> return all -1 or all 0 results. */
>/* ??? We could instead convert all instances of the vec_cond to
>negate,
>--- gcc/testsuite/gcc.dg/tree-ssa/pr96232-1.c.jj 2020-12-05
>11:37:27.804332875 +0100
>+++ gcc/testsuite/gcc.dg/tree-ssa/pr96232-1.c 2020-12-05
>11:37:27.804332875 +0100
>@@ -0,0 +1,11 @@
>+/* PR tree-optimization/96232 */
>+/* { dg-do compile } */
>+/* { dg-options "-O2 -fdump-tree-optimized" } */
>+/* { dg-final { scan-tree-dump " \\+ -1;" "optimized" } } */
>+/* { dg-final { scan-tree-dump-not "~x_\[0-9]*\\\(D\\\)" "optimized" }
>} */
>+
>+int
>+foo (_Bool x)
>+{
>+ return x ? 0 : -1;
>+}
>
>
> Jakub
prev parent reply other threads:[~2020-12-05 12:51 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-12-05 9:10 [PATCH] phiopt: " Jakub Jelinek
2020-12-05 10:20 ` Richard Biener
2020-12-05 10:57 ` [PATCH] match.pd: " Jakub Jelinek
2020-12-05 12:51 ` 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=C2453312-207C-4E3F-9A2D-1491E8731146@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).