[PATCH] D156404: [RISCV] Use x0 in vsetvli when avl is equal to vlmax.
Jianjian Guan via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 27 02:30:33 PDT 2023
jacquesguan created this revision.
jacquesguan added reviewers: craig.topper, asb, luismarques, frasercrmck.
Herald added subscribers: jobnoorman, luke, VincentWu, vkmr, apazos, sameer.abuasal, s.egerton, Jim, benna, psnobl, jocewei, PkmX, the_o, brucehoult, MartinMosbeck, rogfer01, edward-jones, zzheng, jrtc27, shiva0217, kito-cheng, niosHD, sabuasal, simoncook, johnrusso, rbar, hiraditya, arichardson.
Herald added a project: All.
jacquesguan requested review of this revision.
Herald added subscribers: llvm-commits, wangpc, eopXD, MaskRay.
Herald added a project: LLVM.
We could use x0 form in vsetvli when we already know the vlmax and avl is equal to it.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D156404
Files:
llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp
llvm/test/CodeGen/RISCV/rvv/vsetvli-intrinsics.ll
Index: llvm/test/CodeGen/RISCV/rvv/vsetvli-intrinsics.ll
===================================================================
--- llvm/test/CodeGen/RISCV/rvv/vsetvli-intrinsics.ll
+++ llvm/test/CodeGen/RISCV/rvv/vsetvli-intrinsics.ll
@@ -1,8 +1,14 @@
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
; RUN: sed 's/iXLen/i32/g' %s | llc -mtriple=riscv32 -mattr=+v \
-; RUN: -verify-machineinstrs | FileCheck %s
+; RUN: -verify-machineinstrs | FileCheck %s --check-prefixes=CHECK,VLENUNKONWN
; RUN: sed 's/iXLen/i64/g' %s | llc -mtriple=riscv64 -mattr=+v \
-; RUN: -verify-machineinstrs | FileCheck %s
+; RUN: -verify-machineinstrs | FileCheck %s --check-prefixes=CHECK,VLENUNKONWN
+; RUN: sed 's/iXLen/i32/g' %s | llc -mtriple=riscv32 -mattr=+v \
+; RUN: -riscv-v-vector-bits-max=128 -verify-machineinstrs \
+; RUN: | FileCheck %s --check-prefixes=CHECK,VLEN128
+; RUN: sed 's/iXLen/i64/g' %s | llc -mtriple=riscv64 -mattr=+v \
+; RUN: -riscv-v-vector-bits-max=128 -verify-machineinstrs \
+; RUN: | FileCheck %s --check-prefixes=CHECK,VLEN128
declare iXLen @llvm.riscv.vsetvli.iXLen(iXLen, iXLen, iXLen)
declare iXLen @llvm.riscv.vsetvlimax.iXLen(iXLen, iXLen)
@@ -135,3 +141,18 @@
%vl = call iXLen @llvm.riscv.vsetvli.iXLen(iXLen -1, iXLen 0, iXLen 0)
ret iXLen %vl
}
+
+define iXLen @test_vsetvli_eqvlmax_e8m8(iXLen %avl) nounwind {
+; VLENUNKONWN-LABEL: test_vsetvli_eqvlmax_e8m8:
+; VLENUNKONWN: # %bb.0:
+; VLENUNKONWN-NEXT: li a0, 128
+; VLENUNKONWN-NEXT: vsetvli a0, a0, e8, m8, ta, ma
+; VLENUNKONWN-NEXT: ret
+;
+; VLEN128-LABEL: test_vsetvli_eqvlmax_e8m8:
+; VLEN128: # %bb.0:
+; VLEN128-NEXT: vsetvli a0, zero, e8, m8, ta, ma
+; VLEN128-NEXT: ret
+ %vl = call iXLen @llvm.riscv.vsetvli.iXLen(iXLen 128, iXLen 0, iXLen 3)
+ ret iXLen %vl
+}
Index: llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp
===================================================================
--- llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp
+++ llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp
@@ -552,6 +552,13 @@
SDValue VLOperand;
unsigned Opcode = RISCV::PseudoVSETVLI;
+ if (auto *C = dyn_cast<ConstantSDNode>(Node->getOperand(1))) {
+ if (Subtarget->getRealMinVLen() == Subtarget->getRealMaxVLen()) {
+ const unsigned VLEN = Subtarget->getRealMinVLen();
+ if (VLEN / RISCVVType::getSEWLMULRatio(SEW, VLMul) == C->getZExtValue())
+ VLMax = true;
+ }
+ }
if (VLMax || isAllOnesConstant(Node->getOperand(1))) {
VLOperand = CurDAG->getRegister(RISCV::X0, XLenVT);
Opcode = RISCV::PseudoVSETVLIX0;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D156404.544662.patch
Type: text/x-patch
Size: 2603 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230727/83ed7b92/attachment.bin>
More information about the llvm-commits
mailing list