[PING][PATCH] RISC-V: Avoid redundant sign-extension for SImode SGE, SGEU, SLE, SLEU
Hi Kito, On Fri, 12 Aug 2022, Maciej W. Rozycki 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: > >sgtua0,a0,a1# 9 [c=4 l=4] *sgtu_disi > >xoria0,a0,1 # 10[c=4 l=4] *xorsi3_internal/1 > >andia0,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. Maciej
Re: [PING][PATCH] RISC-V: Avoid redundant sign-extension for SImode SGE, SGEU, SLE, SLEU
On 11/25/22 07:07, Maciej W. Rozycki wrote: Hi Kito, On Fri, 12 Aug 2022, Maciej W. Rozycki 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: sgtua0,a0,a1# 9 [c=4 l=4] *sgtu_disi xoria0,a0,1 # 10[c=4 l=4] *xorsi3_internal/1 andia0,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? Jeff
Re: [PING][PATCH] RISC-V: Avoid redundant sign-extension for SImode SGE, SGEU, SLE, SLEU
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: > > > > sgtua0,a0,a1# 9 [c=4 l=4] *sgtu_disi > > > > xoria0,a0,1 # 10[c=4 l=4] *xorsi3_internal/1 > > > > andia0,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 when applied on top of: $ riscv64-linux-gnu-gcc --version riscv64-linux-gnu-gcc (GCC) 13.0.0 20221128 (experimental) Not anymore with the whole patch applied. Does it make sense to bisect the change that removed the pessimisation at -O2 to understand what is going on here? I think my change is worthwhile anyway: why to rely on the optimiser to get things sorted while we can produce the best code in the backend right away in the first place? Maciej
Re: [PING][PATCH] RISC-V: Avoid redundant sign-extension for SImode SGE, SGEU, SLE, SLEU
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: sgtua0,a0,a1# 9 [c=4 l=4] *sgtu_disi xoria0,a0,1 # 10[c=4 l=4] *xorsi3_internal/1 andia0,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 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