From: Philipp Tomsich <philipp.tomsich@vrull.eu>
To: Jeff Law <jeffreyalaw@gmail.com>
Cc: Manolis Tsamis <manolis.tsamis@vrull.eu>,
gcc-patches@gcc.gnu.org,
Richard Biener <richard.guenther@gmail.com>
Subject: Re: [PATCH v1] [RFC] Improve folding for comparisons with zero in tree-ssa-forwprop.
Date: Thu, 16 Mar 2023 21:32:37 +0100 [thread overview]
Message-ID: <CAAeLtUB+A+KNsnX-59-sQkYysuDKNOLVy1WeUBoCY4axVFOVfg@mail.gmail.com> (raw)
In-Reply-To: <dab5c4fd-8053-3ffe-67d1-f1ca3a7c5ee8@gmail.com>
[-- Attachment #1: Type: text/plain, Size: 2329 bytes --]
Just to add a bit more color on this one...
It was originally observed (and isolated from)
_ZN11xalanc_1_1027XalanReferenceCountedObject12addReferenceEPS0_ and
reproduces both for AArch64 and RISC-V.
The basic block (annotated with dynamic instructions executed and
percentage of total dynamic instructions) looks as follows:
> 0x0000000000511488 4589868875 0.4638%
> _ZN11xalanc_1_1027XalanReferenceCountedObject12addReferenceEPS0_
> 4518 lw a4,8(a0)
> 0017029b addiw t0,a4,1
> 00552423 sw t0,8(a0)
> 4685 addi a3,zero,1
> 00d28363 beq t0,a3,6 # 0x51149a
This change reduces the instruction count on RISC-V by one compressible
instruction (2 bytes) and on AArch64 by one instruction (4 bytes).
No execution time improvement (measured on Neoverse-N1) — as would be
expected.
--Philipp.
On Thu, 16 Mar 2023 at 17:41, Jeff Law <jeffreyalaw@gmail.com> wrote:
>
>
> On 3/16/23 09:27, Manolis Tsamis wrote:
> > For this C testcase:
> >
> > void g();
> > void f(unsigned int *a)
> > {
> > if (++*a == 1)
> > g();
> > }
> >
> > GCC will currently emit a comparison with 1 by using the value
> > of *a after the increment. This can be improved by comparing
> > against 0 and using the value before the increment. As a result
> > there is a potentially shorter dependancy chain (no need to wait
> > for the result of +1) and on targets with compare zero instructions
> > the generated code is one instruction shorter.
> >
> > Example from Aarch64:
> >
> > Before
> > ldr w1, [x0]
> > add w1, w1, 1
> > str w1, [x0]
> > cmp w1, 1
> > beq .L4
> > ret
> >
> > After
> > ldr w1, [x0]
> > add w2, w1, 1
> > str w2, [x0]
> > cbz w1, .L4
> > ret
> >
> > gcc/ChangeLog:
> >
> > * tree-ssa-forwprop.cc (combine_cond_expr_cond):
> > (forward_propagate_into_comparison_1): Optimize
> > for zero comparisons.
> Deferring to gcc-14. Though I'm generally supportive of normalizing to
> a comparison against zero when we safely can :-)
>
> jeff
>
next prev parent reply other threads:[~2023-03-16 20:32 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-16 15:27 Manolis Tsamis
2023-03-16 16:41 ` Jeff Law
2023-03-16 20:32 ` Philipp Tomsich [this message]
2023-03-17 8:31 ` Richard Biener
2023-03-17 13:15 ` Philipp Tomsich
2023-03-17 14:03 ` Richard Biener
2023-03-17 20:43 ` Andrew Waterman
2023-03-17 14:12 ` Andrew MacLeod
2023-03-20 14:01 ` Manolis Tsamis
2023-03-23 23:27 ` Jeff Law
2023-04-21 21:01 ` Philipp Tomsich
2023-04-24 8:06 ` Richard Biener
2023-04-24 23:05 ` Jeff Law
2023-04-25 7:21 ` Richard Biener
2023-04-26 2:30 ` Jeff Law
2023-04-26 6:41 ` Richard Biener
2023-08-02 14:07 ` Manolis Tsamis
2023-08-03 7:04 ` Richard Biener
2023-08-03 15:21 ` Jeff Law
2023-08-04 6:37 ` Richard Biener
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=CAAeLtUB+A+KNsnX-59-sQkYysuDKNOLVy1WeUBoCY4axVFOVfg@mail.gmail.com \
--to=philipp.tomsich@vrull.eu \
--cc=gcc-patches@gcc.gnu.org \
--cc=jeffreyalaw@gmail.com \
--cc=manolis.tsamis@vrull.eu \
--cc=richard.guenther@gmail.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).