public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jeff Law <jeffreyalaw@gmail.com>
To: Vineet Gupta <vineetg@rivosinc.com>,
	gcc-patches@gcc.gnu.org, Robin Dapp <rdapp.gcc@gmail.com>
Cc: kito.cheng@gmail.com, Palmer Dabbelt <palmer@rivosinc.com>,
	gnu-toolchain@rivosinc.com,
	Roger Sayle <roger@nextmovesoftware.com>,
	Jakub Jelinek <jakub@redhat.com>,
	Jivan Hakobyan <jivanhakobyan9@gmail.com>
Subject: Re: [RFC] expr: don't clear SUBREG_PROMOTED_VAR_P flag for a promoted subreg [target/111466]
Date: Wed, 4 Oct 2023 11:59:34 -0600	[thread overview]
Message-ID: <e9e655ed-b745-41e4-a0d2-390233699a95@gmail.com> (raw)
In-Reply-To: <20230928214341.257862-1-vineetg@rivosinc.com>



On 9/28/23 15:43, Vineet Gupta wrote:
> RISC-V suffers from extraneous sign extensions, despite/given the ABI
> guarantee that 32-bit quantities are sign-extended into 64-bit registers,
> meaning incoming SI function args need not be explicitly sign extended
> (so do SI return values as most ALU insns implicitly sign-extend too.)
> 
> Existing REE doesn't seem to handle this well and there are various ideas
> floating around to smarten REE about it.
> 
> RISC-V also seems to correctly implement middle-end hook PROMOTE_MODE
> etc.
> 
> Another approach would be to prevent EXPAND from generating the
> sign_extend in the first place which this patch tries to do.
> 
> The hunk being removed was introduced way back in 1994 as
>     5069803972 ("expand_expr, case CONVERT_EXPR .. clear the promotion flag")
> 
> This survived full testsuite run for RISC-V rv64gc with surprisingly no
> fallouts: test results before/after are exactly same.
> 
> |                               | # of unexpected case / # of unique unexpected case
> |                               |          gcc |          g++ |     gfortran |
> | rv64imafdc_zba_zbb_zbs_zicond/|  264 /    87 |    5 /     2 |   72 /    12 |
> |    lp64d/medlow
> 
> Granted for something so old to have survived, there must be a valid
> reason. Unfortunately the original change didn't have additional
> commentary or a test case. That is not to say it can't/won't possibly
> break things on other arches/ABIs, hence the RFC for someone to scream
> that this is just bonkers, don't do this :-)
> 
> I've explicitly CC'ed Jakub and Roger who have last touched subreg
> promoted notes in expr.cc for insight and/or screaming ;-)
> 
> Thanks to Robin for narrowing this down in an amazing debugging session
> @ GNU Cauldron.
> 
> ```
> foo2:
> 	sext.w	a6,a1             <-- this goes away
> 	beq	a1,zero,.L4
> 	li	a5,0
> 	li	a0,0
> .L3:
> 	addw	a4,a2,a5
> 	addw	a5,a3,a5
> 	addw	a0,a4,a0
> 	bltu	a5,a6,.L3
> 	ret
> .L4:
> 	li	a0,0
> 	ret
> ```
> 
> Signed-off-by: Vineet Gupta <vineetg@rivosinc.com>
> Co-developed-by: Robin Dapp <rdapp.gcc@gmail.com>
> ---
>   gcc/expr.cc                               |  7 -------
>   gcc/testsuite/gcc.target/riscv/pr111466.c | 15 +++++++++++++++
>   2 files changed, 15 insertions(+), 7 deletions(-)
>   create mode 100644 gcc/testsuite/gcc.target/riscv/pr111466.c
So mcore-elf is showing something interesting.  With that hunk of Kenner 
code removed, it actually has a few failing tests that flip to passes.

> Tests that now work, but didn't before (11 tests):
> 
> mcore-sim: gcc.c-torture/execute/pr109986.c   -O1  execution test
> mcore-sim: gcc.c-torture/execute/pr109986.c   -O2  execution test
> mcore-sim: gcc.c-torture/execute/pr109986.c   -O2 -flto -fno-use-linker-plugin -flto-partition=none  execution test
> mcore-sim: gcc.c-torture/execute/pr109986.c   -O2 -flto -fuse-linker-plugin -fno-fat-lto-objects  execution test
> mcore-sim: gcc.c-torture/execute/pr109986.c   -O3 -g  execution test
> mcore-sim: gcc.c-torture/execute/pr109986.c   -Os  execution test
> mcore-sim: gcc.c-torture/execute/pr84524.c   -O2  execution test
> mcore-sim: gcc.c-torture/execute/pr84524.c   -O2 -flto -fno-use-linker-plugin -flto-partition=none  execution test
> mcore-sim: gcc.c-torture/execute/pr84524.c   -O2 -flto -fuse-linker-plugin -fno-fat-lto-objects  execution test
> mcore-sim: gcc.dg/tree-ssa/pr84436-5.c execution test
> mcore-sim: gcc.dg/tree-ssa/pr84436-5.c execution test

So that's a really interesting result.   If further analysis doesn't 
point the finger at a simulator bug or something like that, then we'll 
have strong evidence that Kenner's change is actively harmful from a 
correctness standpoint.  That would change the calculus here significantly.

Sadly, mcore-elf doesn't have a working gdb IIRC (don't ask how I know 
that!), so I'm going to have to analyze this further with less efficient 
techniques.  BUt definitely interesting news/results.

Jeff

  parent reply	other threads:[~2023-10-04 17:59 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-28 21:43 Vineet Gupta
2023-09-29  3:17 ` Jeff Law
2023-09-29  3:49   ` Vineet Gupta
2023-09-29 12:14     ` Jeff Law
2023-10-03  1:29       ` Vineet Gupta
2023-10-05 14:56   ` Richard Kenner
2023-10-05 15:04     ` Jeff Law
2023-09-29 10:40 ` Roger Sayle
2023-09-29 13:43   ` Jeff Law
2023-10-04 15:29 ` Jeff Law
2023-10-04 17:59 ` Jeff Law [this message]
2023-10-04 18:14   ` Vineet Gupta
2023-10-04 20:11     ` Jeff Law
2023-10-05  4:49 ` Jeff Law
2023-10-05 13:33   ` Robin Dapp
2023-10-05 16:42     ` Jeff Law
2023-10-12  2:37 ` Hans-Peter Nilsson
2023-10-12 16:11   ` Vineet Gupta
2023-10-17  4:07 ` Jeff Law
2023-10-17 18:06   ` Vineet Gupta
2023-10-17 18:07   ` [PATCH] RISC-V/testsuite/pr111466.c: fix expected output to not detect SEXT.W Vineet Gupta
2023-10-17 18:51     ` [PATCH v2] RISC-V/testsuite/pr111466.c: update test and expected output Vineet Gupta
2023-10-17 19:45       ` Jeff Law
2023-10-17 20:14         ` [COMMITTED] " Vineet Gupta

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=e9e655ed-b745-41e4-a0d2-390233699a95@gmail.com \
    --to=jeffreyalaw@gmail.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=gnu-toolchain@rivosinc.com \
    --cc=jakub@redhat.com \
    --cc=jivanhakobyan9@gmail.com \
    --cc=kito.cheng@gmail.com \
    --cc=palmer@rivosinc.com \
    --cc=rdapp.gcc@gmail.com \
    --cc=roger@nextmovesoftware.com \
    --cc=vineetg@rivosinc.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).