From: 钟居哲 <juzhe.zhong@rivai.ai>
To: "Jeff Law" <jeffreyalaw@gmail.com>,
gcc-patches <gcc-patches@gcc.gnu.org>
Cc: kito.cheng <kito.cheng@gmail.com>,
kito.cheng <kito.cheng@sifive.com>,
rdapp.gcc <rdapp.gcc@gmail.com>,
"Joern Rennecke" <joern.rennecke@embecosm.com>
Subject: Re: Re: cpymem for RISCV with v extension
Date: Sat, 5 Aug 2023 07:44:26 +0800 [thread overview]
Message-ID: <9285239D8F8951E9+2023080507442558553526@rivai.ai> (raw)
In-Reply-To: <5814e96a-9d86-d428-cf48-ec1ab80eb2d9@gmail.com>
[-- Attachment #1: Type: text/plain, Size: 6641 bytes --]
>> Umm, this patch has been queued up for at least a couple weeks now.
Oh. I am sorry I didn't see this patch since this patch doesn't CC me.
I didn't subscribe GCC-patch, so I may miss some patches that didn't explicitly CC me.
I just happen to see your reply email today then reply.
juzhe.zhong@rivai.ai
From: Jeff Law
Date: 2023-08-05 07:17
To: 钟居哲; gcc-patches
CC: kito.cheng; kito.cheng; rdapp.gcc; Joern Rennecke
Subject: Re: cpymem for RISCV with v extension
On 8/4/23 17:10, 钟居哲 wrote:
> Could you add testcases for this patch?
Testing what specifically? Are you asking for correctness tests,
performance/code quality tests?
>
> +;; The (use (and (match_dup 1) (const_int 127))) is here to prevent the
> +;; optimizers from changing cpymem_loop_* into this.
> +(define_insn "@cpymem_straight<P:mode><V_WHOLE:mode>"
> + [(set (mem:BLK (match_operand:P 0 "register_operand" "r,r"))
> + (mem:BLK (match_operand:P 1 "register_operand" "r,r")))
> + (use (and (match_dup 1) (const_int 127)))
> + (use (match_operand:P 2 "reg_or_int_operand" "r,K"))
> + (clobber (match_scratch:V_WHOLE 3 "=&vr,&vr"))
> + (clobber (reg:SI VL_REGNUM))
> + (clobber (reg:SI VTYPE_REGNUM))]
> + "TARGET_VECTOR"
> + "@vsetvli zero,%2,e<sew>,m8,ta,ma\;vle<sew>.v %3,(%1)\;vse<sew>.v %3,(%0)
> + vsetivli zero,%2,e<sew>,m8,ta,ma\;vle<sew>.v %3,(%1)\;vse<sew>.v %3,(%0)"
> +)
> +
> +(define_insn "@cpymem_loop<P:mode><V_WHOLE:mode>"
> + [(set (mem:BLK (match_operand:P 0 "register_operand" "+r"))
> + (mem:BLK (match_operand:P 1 "register_operand" "+r")))
> + (use (match_operand:P 2 "register_operand" "+r"))
> + (clobber (match_scratch:V_WHOLE 3 "=&vr"))
> + (clobber (match_scratch:P 4 "=&r"))
> + (clobber (match_dup 0))
> + (clobber (match_dup 1))
> + (clobber (match_dup 2))
> + (clobber (reg:SI VL_REGNUM))
> + (clobber (reg:SI VTYPE_REGNUM))]
> + "TARGET_VECTOR"
> +{ output_asm_insn ("\n0:\t" "vsetvli %4,%2,e<sew>,m8,ta,ma\;"
> + "vle<sew>.v %3,(%1)\;"
> + "sub %2,%2,%4", operands);
> + if (<sew> != 8)
> + {
> + rtx xop[2];
> + xop[0] = operands[4];
> + xop[1] = GEN_INT (exact_log2 (<sew>/8));
> + output_asm_insn ("slli %0,%0,%1", xop);
> + }
> + output_asm_insn ("add %1,%1,%4\;"
> + "vse<sew>.v %3,(%0)\;"
> + "add %0,%0,%4\;"
> + "bnez %2,0b", operands);
> + return "";
> +})
> +
> +;; This pattern (at bltu) assumes pointers can be treated as unsigned,
> +;; i.e. objects can't straddle 0xffffffffffffffff / 0x0000000000000000 .
> +(define_insn "@cpymem_loop_fast<P:mode><V_WHOLE:mode>"
> + [(set (mem:BLK (match_operand:P 0 "register_operand" "+r"))
> + (mem:BLK (match_operand:P 1 "register_operand" "+r")))
> + (use (match_operand:P 2 "register_operand" "+r"))
> + (clobber (match_scratch:V_WHOLE 3 "=&vr"))
> + (clobber (match_scratch:P 4 "=&r"))
> + (clobber (match_scratch:P 5 "=&r"))
> + (clobber (match_scratch:P 6 "=&r"))
> + (clobber (match_dup 0))
> + (clobber (match_dup 1))
> + (clobber (match_dup 2))
> + (clobber (reg:SI VL_REGNUM))
> + (clobber (reg:SI VTYPE_REGNUM))]
> + "TARGET_VECTOR"
> +{
> + output_asm_insn ("vsetvli %4,%2,e<sew>,m8,ta,ma\;"
> + "beq %4,%2,1f\;"
> + "add %5,%0,%2\;"
> + "sub %6,%5,%4", operands);
> + if (<sew> != 8)
> + {
> + rtx xop[2];
> + xop[0] = operands[4];
> + xop[1] = GEN_INT (exact_log2 (<sew>/8));
> + output_asm_insn ("slli %0,%0,%1", xop);
> + }
> + output_asm_insn ("\n0:\t" "vle<sew>.v %3,(%1)\;"
> + "add %1,%1,%4\;"
> + "vse<sew>.v %3,(%0)\;"
> + "add %0,%0,%4\;"
>>> "bltu %0,%6,0b\;"
>>> "sub %5,%5,%0", operands);
>>> if (<sew> != 8)
>>> {
>>> rtx xop[2];
>>> xop[0] = operands[4];
>>> xop[1] = GEN_INT (exact_log2 (<sew>/8));
>>> output_asm_insn ("srli %0,%0,%1", xop);
>>> }
>>> output_asm_insn ("vsetvli %4,%5,e<sew>,m8,ta,ma\n"
>>> "1:\t" "vle<sew>.v %3,(%1)\;"
>>> "vse<sew>.v %3,(%0)", operands);
>>> return "";
>>> })
>
> I don't think they are necessary.
What specifically do you think is not necessary?
>
>>> Just post the update for archival purposes and consider
>>> it pre-approved for the trunk.
>
> I am so sorry that I disagree approve this patch too fast.
Umm, this patch has been queued up for at least a couple weeks now.
>
> It should be well tested.
If you refer to Joern's message he indicated how it was tested. Joern
is a long time GCC developer and is well aware of how to test code.
It was tested on this set of multilibs without regressions:
> riscv-sim
> riscv-sim/-march=rv32imafdcv_zicsr_zifencei_zfh_zba_zbb_zbc_zbs_zve32f_zve32x_zve64d_zve64f_zve64x_zvl128b_zvl32b_zvl64b/-mabi=ilp32f
> riscv-sim/-march=rv32imafdcv_zicsr_zifencei_zfh_zve32f_zve32x_zve64d_zve64f_zve64x_zvl128b_zvl32b_zvl64b/-mabi=ilp32
> riscv-sim/-march=rv32imafdcv_zicsr_zifencei_zfh_zve32f_zve32x_zve64d_zve64f_zve64x_zvl128b_zvl32b_zvl64b/-mabi=ilp32f
> riscv-sim/-march=rv32imfdcv_zicsr_zifencei_zfh_zve32f_zve32x_zve64d_zve64f_zve64x_zvl128b_zvl32b_zvl64b/-mabi=ilp32
> riscv-sim/-march=rv64imafdcv_zicsr_zifencei_zfh_zba_zbb_zbc_zbs_zve32f_zve32x_zve64d_zve64f_zve64x_zvl128b_zvl32b_zvl64b/-mabi=lp64d
> riscv-sim/-march=rv64imafdcv_zicsr_zifencei_zfh_zba_zbb_zbs_zve32f_zve32x_zve64d_zve64f_zve64x_zvl128b_zvl32b_zvl64b/-mabi=lp64d
> riscv-sim/-march=rv64imafdcv_zicsr_zifencei_zfh_zve32f_zve32x_zve64d_zve64f_zve64x_zvl128b_zvl32b_zvl64b/-mabi=lp64d
>
>
> We should at least these 2 following situations:
>
> 1. an unknown number bytes to be memcpy, this codegen should be as follows:
>
> vsetvl a5,a2,e8,m8,ta,ma
>
> vle
>
> vse
>
> bump counter
>
> branch
>
> 2. a known number bytes to be memcpy, and the number bytes allow us to
> fine a VLS modes to hold it.
>
> For example, memcpy 16 bytes QImode.
>
> Then, we can use V16QImode directly, the codegen should be:
>
> vsetvli zero,16,....
>
> vle
>
> vse
>
> Simple 3 instructions are enough.
>
>
> This patch should be well tested with these 2 situations before approved
> since LLVM does the same thing.
>
> We should be able to have the same behavior as LLVM.
I'm not sure that's strictly necessary and I don't mind iterating a bit
on performance issues as long as we don't have correctness problems.
But since you've raised concerns -- Joern don't install until we've
resolved the questions at hand. Thanks.
jeff
prev parent reply other threads:[~2023-08-04 23:44 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-04 23:10 钟居哲
2023-08-04 23:17 ` Jeff Law
2023-08-04 23:34 ` 钟居哲
2023-08-15 8:12 ` Joern Rennecke
2023-08-15 9:16 ` juzhe.zhong
2023-08-15 14:06 ` Jeff Law
2023-10-02 2:43 ` [RISC-V]: " Joern Rennecke
2023-10-04 17:38 ` Patrick O'Neill
2023-10-04 19:19 ` Joern Rennecke
2023-10-04 21:35 ` Patrick O'Neill
2023-08-15 14:04 ` Jeff Law
2023-08-04 23:44 ` 钟居哲 [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=9285239D8F8951E9+2023080507442558553526@rivai.ai \
--to=juzhe.zhong@rivai.ai \
--cc=gcc-patches@gcc.gnu.org \
--cc=jeffreyalaw@gmail.com \
--cc=joern.rennecke@embecosm.com \
--cc=kito.cheng@gmail.com \
--cc=kito.cheng@sifive.com \
--cc=rdapp.gcc@gmail.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).