[RISCV][CodeGen] Vector `Not(Sne)` sequences produced that can be simplified to `Seq`
Found when reviewing #221321.
llc -mtriple=riscv64 -mcpu=sifive-p670 -verify-machineinstrs
define i1 @all_8(ptr %input) {
entry:
%tmp0 = load <8 x i8>, ptr %input, align 1
%tmp1 = trunc <8 x i8> %tmp0 to <8 x i1>
%tmp2 = call i1 @llvm.vector.reduce.and.v32i1(<8 x i1> %tmp1)
ret i1 %tmp2
}
results in
vsetivli zero, 8, e8, mf2, ta, ma
vle8.v v8, (a0)
vand.vi v8, v8, 1
vmsne.vi v8, v8, 0
vmnot.m v8, v8
vcpop.m a0, v8
seqz a0, a0
ret
Two separate issues here:
- The
vmsne.vi - vmnotsequence can be simplified tovmseq
vsetivli zero, 8, e8, mf2, ta, ma
vle8.v v8, (a0)
vand.vi v8, v8, 1
vmseq.vi v8, v8, 0
vcpop.m a0, v8
seqz a0, a0
ret
- Could be instead lower to. Might be better handled in
vector-combine(i.e. reverse the ordering of thetruncandreduce.and)
vsetivli zero, 8, e8, mf2, ta, ma
vle8.v v8, (a0)
vredand.vs v8, v8, v8
vmv.x.s a0, v8
ret
@llvm/issue-subscribers-backend-risc-v
Author: Ryan Buchner (bababuck)
llc -mtriple=riscv64 -mcpu=sifive-p670 -verify-machineinstrs
define i1 @<!-- -->all_8(ptr %input) {
entry:
%tmp0 = load <8 x i8>, ptr %input, align 1
%tmp1 = trunc <8 x i8> %tmp0 to <8 x i1>
%tmp2 = call i1 @<!-- -->llvm.vector.reduce.and.v32i1(<8 x i1> %tmp1)
ret i1 %tmp2
}
results in
vsetivli zero, 8, e8, mf2, ta, ma
vle8.v v8, (a0)
vand.vi v8, v8, 1
vmsne.vi v8, v8, 0
vmnot.m v8, v8
vcpop.m a0, v8
seqz a0, a0
ret
Two separate issues here:
- The
vmsne.vi - vmnotsequence can be simplified tovmseq
vsetivli zero, 8, e8, mf2, ta, ma
vle8.v v8, (a0)
vand.vi v8, v8, 1
vmseq.vi v8, v8, 0
vcpop.m a0, v8
seqz a0, a0
ret
- Could be instead lower to. Might be better handled in
vector-combine(i.e. reverse the ordering of thetruncandreduce.and)
vsetivli zero, 8, e8, mf2, ta, ma
vle8.v v8, (a0)
vredand.vs v8, v8, v8
vmv.x.s a0, v8
ret
Hi! I'd like to work on this issue. If no one else is already working on it, please assign it to me. Thanks!
Hi! I'd like to work on this issue. If no one else is already working on it, please assign it to me. Thanks!
Assigned. I'm not quite sure of the direction to take this. My understanding is that the trunc and the reduce.and get lowered separately, creating the vmseq and the vmnot independently. I'm not 100% of the best path to fixing this, might be worth getting input from some of the other RISCV contributors if you're not sure either.
Edit: Forgot to say thanks for picking this up :)
Hi!
This issue may be a good introductory issue for people new to working on LLVM. If you would like to work on this issue, your first steps are:
- Check that no other contributor is working on this issue. If someone is assigned to the issue or claimed to be working on it, ping the person. After one week without a response, the assignee may be changed.
- Leave a comment indicating that you are working on the issue, or just create a pull request after following the steps below. Mention this issue in the description of the pull request.
- Fix the issue locally. Be aware that LLVM's AI policy forbids the use of AI tools to fix good first issues since it squanders a learning opportunity. Using LLMs to search and learn is permitted, since the goal is learning.
- Run the test suite locally. Remember that the subdirectories under
test/create fine-grained testing targets, so you can e.g. usemake check-clang-astto only run Clang's AST tests. - Create a Git commit.
- Run
git clang-format HEAD~1to format your changes. - Open a pull request to the upstream repository on GitHub. Detailed instructions can be found in GitHub's documentation. Mention this issue in the description of the pull request.
If you have any further questions about this issue, don't hesitate to ask via a comment in the thread below.
@llvm/issue-subscribers-good-first-issue
Author: Ryan Buchner (bababuck)
llc -mtriple=riscv64 -mcpu=sifive-p670 -verify-machineinstrs
define i1 @<!-- -->all_8(ptr %input) {
entry:
%tmp0 = load <8 x i8>, ptr %input, align 1
%tmp1 = trunc <8 x i8> %tmp0 to <8 x i1>
%tmp2 = call i1 @<!-- -->llvm.vector.reduce.and.v32i1(<8 x i1> %tmp1)
ret i1 %tmp2
}
results in
vsetivli zero, 8, e8, mf2, ta, ma
vle8.v v8, (a0)
vand.vi v8, v8, 1
vmsne.vi v8, v8, 0
vmnot.m v8, v8
vcpop.m a0, v8
seqz a0, a0
ret
Two separate issues here:
- The
vmsne.vi - vmnotsequence can be simplified tovmseq
vsetivli zero, 8, e8, mf2, ta, ma
vle8.v v8, (a0)
vand.vi v8, v8, 1
vmseq.vi v8, v8, 0
vcpop.m a0, v8
seqz a0, a0
ret
- Could be instead lower to. Might be better handled in
vector-combine(i.e. reverse the ordering of thetruncandreduce.and)
vsetivli zero, 8, e8, mf2, ta, ma
vle8.v v8, (a0)
vredand.vs v8, v8, v8
vmv.x.s a0, v8
ret
@Adarsh-Me This looks like a good first issue for contributors to learn, typically these don't need to be assigned to anyone but feel free to open up a PR for it regardless. As a heads up, LLMs aren't allowed to fix good first issues as per the AI policy: https://llvm.org/docs/AIToolPolicy.html#details
Hi im new to this and trying to learn LLVM. Can I try to do this?
Hi, Please can you assigned this to me if Your not working. Please Assign it to me. I am new here
Hey, If no one is assigned, i'd like to try working on it. Thanks,
Hi @bababuck @lukel97 I opened a PR :)