public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Vineet Gupta <vineetg@rivosinc.com>
To: Palmer Dabbelt <palmer@rivosinc.com>
Cc: gcc-patches@gcc.gnu.org, manolis.tsamis@vrull.eu,
	Kito Cheng <kito.cheng@gmail.com>,
	jeffreyalaw@gmail.com, gnu-toolchain@rivosinc.com
Subject: Re: [PATCH] RISC-V: optim const DF +0.0 store to mem [PR/110748]
Date: Fri, 21 Jul 2023 12:37:01 -0700	[thread overview]
Message-ID: <4e2be0d2-2c8c-4f8f-1a81-5b387447243a@rivosinc.com> (raw)
In-Reply-To: <mhng-f7a482fe-7b57-4f20-b75a-a1cc99c542cf@palmer-ri-x1c9a>



On 7/21/23 11:31, Palmer Dabbelt wrote:
>
> IIUC the pattern to emit fmv suffers from the same bug -- it's fixed 
> in the same
> way, but I think we might be able to come up with a test for it: 
> `fmv.d.x FREG,
> x0` would be the fastest way to generate 0.0, so maybe something like
>
>    double sum(double *d) {
>      double sum = 0;
>      for (int i = 0; i < 8; ++i)
>        sum += d[i];
>      return sum;
>    }
>
> would do it?  That's generating the fmv on 13 for me, though, so maybe 
> I'm
> missing something?` 

I don't think we can avoid FMV in this case

     fmv.d.x    fa0,zero     #1
     addi    a5,a0,64
.L2:
     fld    fa5,0(a0)
     addi    a0,a0,8
     fadd.d    fa0,fa0,fa5   #2
     bne    a0,a5,.L2
     ret

In #1, the zero needs to be setup in FP reg (possible using FMV), since 
in #2 it will be used for FP math.

If we change ur test slightly,

double zadd(double *d) {
      double sum = 0.0;
      for (int i = 0; i < 8; ++i)
        d[i] = sum;
      return sum;
}

We still get the optimal code for writing to FP 0. The last FMV is 
unavoidable as we need an FP return reg.


     addi    a5,a0,64
.L2:
     sd    zero,0(a0)
     addi    a0,a0,8
     bne    a0,a5,.L2
     fmv.d.x    fa0,zero
     ret

      parent reply	other threads:[~2023-07-21 19:37 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-21 17:55 Vineet Gupta
2023-07-21 18:15 ` Philipp Tomsich
2023-07-21 18:23   ` Vineet Gupta
2023-07-21 18:31 ` Palmer Dabbelt
2023-07-21 18:47   ` Jeff Law
2023-07-25 23:05     ` Palmer Dabbelt
2023-07-26  3:09       ` Jeff Law
2023-07-21 18:55   ` Vineet Gupta
2023-07-22  6:03     ` Jeff Law
2023-07-21 19:37   ` Vineet Gupta [this message]

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=4e2be0d2-2c8c-4f8f-1a81-5b387447243a@rivosinc.com \
    --to=vineetg@rivosinc.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=gnu-toolchain@rivosinc.com \
    --cc=jeffreyalaw@gmail.com \
    --cc=kito.cheng@gmail.com \
    --cc=manolis.tsamis@vrull.eu \
    --cc=palmer@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).