public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jeff Law <jeffreyalaw@gmail.com>
To: "Maciej W. Rozycki" <macro@embecosm.com>
Cc: Kito Cheng <kito.cheng@gmail.com>,
	GCC Patches <gcc-patches@gcc.gnu.org>,
	Andrew Waterman <andrew@sifive.com>
Subject: Re: [PING][PATCH] RISC-V: Avoid redundant sign-extension for SImode SGE, SGEU, SLE, SLEU
Date: Mon, 28 Nov 2022 09:15:17 -0700	[thread overview]
Message-ID: <85ca8410-376b-5de7-0cfd-c213d8ab0cbd@gmail.com> (raw)
In-Reply-To: <alpine.DEB.2.20.2211281527330.463@tpp.orcam.me.uk>


On 11/28/22 08:38, Maciej W. Rozycki wrote:
> On Mon, 28 Nov 2022, Jeff Law wrote:
>
>>>>> LGTM, but with a nit, I don't get set.w but get an andi like below, so
>>>>> maybe we should also scan-assembler-not andi? feel free to commit that
>>>>> directly with that fix
>>>>>
>>>>> ```asm
>>>>> sleu:
>>>>>          sgtu    a0,a0,a1        # 9     [c=4 l=4]  *sgtu_disi
>>>>>          xori    a0,a0,1 # 10    [c=4 l=4]  *xorsi3_internal/1
>>>>>          andi    a0,a0,1 # 16    [c=4 l=4]  anddi3/1
>>>>>          ret             # 25    [c=0 l=4]  simple_return
>>>>> ```
>>>>    Interesting.  I can do that, but can you please share the compilation
>>>> options, given or defaulted (from `--with...' configuration options), this
>>>> happens with?
>>>    I have noticed it went nowhere.  Can you please check what compilation
>>> options lead to this discrepancy so that we can have the fix included in
>>> GCC 13?  I'd like to understand what's going on here.
>> FWIW, I don't see the redundant sign extension with this testcase at -O2 on
>> the trunk.  Is it possible the patch has been made redundant over the last few
>> months?
>   Maybe at -O2, but the test cases continue to fail in my configuration for
> other optimisation levels:
>
> FAIL: gcc.target/riscv/sge.c   -O1   scan-assembler-not sext\\.w
> FAIL: gcc.target/riscv/sge.c  -Og -g   scan-assembler-not sext\\.w
> FAIL: gcc.target/riscv/sgeu.c   -O1   scan-assembler-not sext\\.w
> FAIL: gcc.target/riscv/sgeu.c  -Og -g   scan-assembler-not sext\\.w
> FAIL: gcc.target/riscv/sle.c   -O1   scan-assembler-not sext\\.w
> FAIL: gcc.target/riscv/sle.c  -Og -g   scan-assembler-not sext\\.w
> FAIL: gcc.target/riscv/sleu.c   -O1   scan-assembler-not sext\\.w
> FAIL: gcc.target/riscv/sleu.c  -Og -g   scan-assembler-not sext\\.w

I may have been running an rv32 toolchain...  So I'll start over and 
ensure that I'm running rv64 :-)


With the trunk, I get code like Kito (AND with 0x1 mask)


The key difference is Roger's patch:

commit c23a9c87cc62bd177fd0d4db6ad34b34e1b9a31f
Author: Roger Sayle <roger@nextmovesoftware.com>
Date:   Wed Aug 3 08:55:35 2022 +0100

     Some additional zero-extension related optimizations in simplify-rtx.

     This patch implements some additional zero-extension and sign-extension
     related optimizations in simplify-rtx.cc.  The original motivation 
comes
     from PR rtl-optimization/71775, where in comment #2 Andrew Pinksi sees:

     Failed to match this instruction:
     (set (reg:DI 88 [ _1 ])
         (sign_extend:DI (subreg:SI (ctz:DI (reg/v:DI 86 [ x ])) 0)))

[ ... ]

With that patch the sign extension is removed and instead we generate 
the AND with 0x1.

Old, from combine dump:

   Successfully matched this instruction:
   (set (reg/i:DI 10 a0)
!     (sign_extend:DI (reg:SI 78)))


New, from combine dump:

   (set (reg/i:DI 10 a0)
!     (and:DI (subreg:DI (reg:SI 78) 0)
!         (const_int 1 [0x1])))

Note the date on Roger's patch, roughly the same time as yours. I 
suspect Kito had tested the truck with Roger's patch.


Your patch is probably still useful.  I think Kito's only concern was to 
make sure we don't have the ANDI instruction in addition to not having 
the SEXT instruction.  So still approved for trunk, just update the 
testcases to make sure we don't have the ANDI too.


jeff



  reply	other threads:[~2022-11-28 16:15 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-03  9:54 [PATCH] " Maciej W. Rozycki
2022-08-11  3:26 ` Kito Cheng
2022-08-12 22:01   ` Maciej W. Rozycki
2022-11-25 14:07     ` [PING][PATCH] " Maciej W. Rozycki
2022-11-28 14:50       ` Jeff Law
2022-11-28 15:38         ` Maciej W. Rozycki
2022-11-28 16:15           ` Jeff Law [this message]
2022-11-28 17:44             ` [PATCH v2] " Maciej W. Rozycki
2022-11-28 18:07               ` Jeff Law
2022-11-28 19:41                 ` Maciej W. Rozycki

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=85ca8410-376b-5de7-0cfd-c213d8ab0cbd@gmail.com \
    --to=jeffreyalaw@gmail.com \
    --cc=andrew@sifive.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=kito.cheng@gmail.com \
    --cc=macro@embecosm.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).