public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Alexander Monakov <amonakov@ispras.ru>
To: Philipp Tomsich <philipp.tomsich@vrull.eu>
Cc: gcc-patches@gcc.gnu.org, Vineet Gupta <vineetg@rivosinc.com>,
	 Kito Cheng <kito.cheng@gmail.com>,
	Jojo R <rjiejie@linux.alibaba.com>,
	 Jeff Law <jlaw@ventanamicro.com>
Subject: Re: [PATCH] riscv: implement TARGET_MODE_REP_EXTENDED
Date: Wed, 9 Nov 2022 20:21:33 +0300 (MSK)	[thread overview]
Message-ID: <b82bf348-d167-43e2-564c-44f5da2eacf@ispras.ru> (raw)
In-Reply-To: <CAAeLtUCESGy=xZVjPP5wvFA2RqKChc4LHib3xXOGrmhVde8R=Q@mail.gmail.com>

On Wed, 9 Nov 2022, Philipp Tomsich wrote:

> > To give a specific example that will be problematic if you go far enough down
> > the road of matching MIPS64 behavior:
> >
> > long f(void)
> > {
> >     int x;
> >     asm("" : "=r"(x));
> >     return x;
> > }
> >
> > here GCC (unlike LLVM) omits sign extension of 'x', assuming that asm output
> > must have been sign-extended to 64 bits by the programmer.
> 
> In fact, with the proposed patch (but also without it), GCC will sign-extend:
> f:
>   sext.w a0,a0
>   ret
>   .size f, .-f

I'm aware. I said "will be problematic if ...", meaning that GCC omits sign
extension when targeting MIPS64, and if you match MIPS64 behavior on RISC-V, 
you'll get in that situation as well.

> To make sure that this is not just an extension to promote the int to
> long for the function return, I next added another empty asm to
> consume 'x'.
> This clearly shows that the extension is performed to postprocess the
> output of the asm-statement:
> 
> f:
>   # ./asm2.c:4:     asm("" : "=r"(x));
>   sext.w a0,a0 # x, x
>   # ./asm2.c:5:     asm("" : : "r"(x));
>   # ./asm2.c:7: }
>   ret

No, you cannot distinguish post-processing the output of the first asm vs.
pre-processing the input of the second asm. Try

  asm("" : "+r"(x));

as the second asm instead, and you'll get

f:
# t.c:17:     asm("" : "=r"(x));
# t.c:18:     asm("" : "+r"(x));
# t.c:20: }
        sext.w  a0,a0   #, x
        ret

If it helps, here's a Compiler Explorer link comparing with MIPS64:
https://godbolt.org/z/7eobvdKdK

Alexander

  reply	other threads:[~2022-11-09 17:21 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-05 21:44 Philipp Tomsich
2022-09-06 11:39 ` Alexander Monakov
2022-09-16 23:48   ` Jeff Law
2022-09-17  7:59     ` Palmer Dabbelt
2022-11-04 23:00   ` Philipp Tomsich
2022-11-05  6:16     ` [PATCH] [PHIOPT] Add A ? B + CST : B match and simplify optimizations Zhongyunde
2022-11-05  6:34       ` Andrew Pinski
2022-11-05  9:03         ` Zhongyunde
2022-11-08 14:58           ` Richard Biener
2022-11-08 15:51             ` 钟云德
2022-11-09  8:00               ` Richard Biener
2022-11-07 13:55     ` [PATCH] riscv: implement TARGET_MODE_REP_EXTENDED Alexander Monakov
2022-11-08 23:45       ` Philipp Tomsich
2022-11-09 17:21         ` Alexander Monakov [this message]
2022-11-20 16:09     ` Jeff Law
2022-11-21 13:49       ` Alexander Monakov
2022-11-21 14:56         ` Jeff Law
2022-11-21 15:33           ` Alexander Monakov

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=b82bf348-d167-43e2-564c-44f5da2eacf@ispras.ru \
    --to=amonakov@ispras.ru \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jlaw@ventanamicro.com \
    --cc=kito.cheng@gmail.com \
    --cc=philipp.tomsich@vrull.eu \
    --cc=rjiejie@linux.alibaba.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).