Skip to content

Commit b7408eb

Browse files
committed
[RISCV] Use x0 in vsetvli when avl is equal to vlmax.
We could use x0 form in vsetvli when we already know the vlmax and avl is equal to it. Reviewed By: craig.topper Differential Revision: https://reviews.llvm.org/D156404
1 parent 75f770a commit b7408eb

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,12 @@ void RISCVDAGToDAGISel::selectVSETVLI(SDNode *Node) {
552552

553553
SDValue VLOperand;
554554
unsigned Opcode = RISCV::PseudoVSETVLI;
555+
if (auto *C = dyn_cast<ConstantSDNode>(Node->getOperand(1))) {
556+
const unsigned VLEN = Subtarget->getRealMinVLen();
557+
if (VLEN == Subtarget->getRealMaxVLen())
558+
if (VLEN / RISCVVType::getSEWLMULRatio(SEW, VLMul) == C->getZExtValue())
559+
VLMax = true;
560+
}
555561
if (VLMax || isAllOnesConstant(Node->getOperand(1))) {
556562
VLOperand = CurDAG->getRegister(RISCV::X0, XLenVT);
557563
Opcode = RISCV::PseudoVSETVLIX0;

llvm/test/CodeGen/RISCV/rvv/vsetvli-intrinsics.ll

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
22
; RUN: sed 's/iXLen/i32/g' %s | llc -mtriple=riscv32 -mattr=+v \
3-
; RUN: -verify-machineinstrs | FileCheck %s
3+
; RUN: -verify-machineinstrs | FileCheck %s --check-prefixes=CHECK,VLENUNKNOWN
44
; RUN: sed 's/iXLen/i64/g' %s | llc -mtriple=riscv64 -mattr=+v \
5-
; RUN: -verify-machineinstrs | FileCheck %s
5+
; RUN: -verify-machineinstrs | FileCheck %s --check-prefixes=CHECK,VLENUNKNOWN
6+
; RUN: sed 's/iXLen/i32/g' %s | llc -mtriple=riscv32 -mattr=+v \
7+
; RUN: -riscv-v-vector-bits-max=128 -verify-machineinstrs \
8+
; RUN: | FileCheck %s --check-prefixes=CHECK,VLEN128
9+
; RUN: sed 's/iXLen/i64/g' %s | llc -mtriple=riscv64 -mattr=+v \
10+
; RUN: -riscv-v-vector-bits-max=128 -verify-machineinstrs \
11+
; RUN: | FileCheck %s --check-prefixes=CHECK,VLEN128
612

713
declare iXLen @llvm.riscv.vsetvli.iXLen(iXLen, iXLen, iXLen)
814
declare iXLen @llvm.riscv.vsetvlimax.iXLen(iXLen, iXLen)
@@ -135,3 +141,18 @@ define iXLen @test_vsetvli_negone_e8m1(iXLen %avl) nounwind {
135141
%vl = call iXLen @llvm.riscv.vsetvli.iXLen(iXLen -1, iXLen 0, iXLen 0)
136142
ret iXLen %vl
137143
}
144+
145+
define iXLen @test_vsetvli_eqvlmax_e8m8(iXLen %avl) nounwind {
146+
; VLENUNKNOWN-LABEL: test_vsetvli_eqvlmax_e8m8:
147+
; VLENUNKNOWN: # %bb.0:
148+
; VLENUNKNOWN-NEXT: li a0, 128
149+
; VLENUNKNOWN-NEXT: vsetvli a0, a0, e8, m8, ta, ma
150+
; VLENUNKNOWN-NEXT: ret
151+
;
152+
; VLEN128-LABEL: test_vsetvli_eqvlmax_e8m8:
153+
; VLEN128: # %bb.0:
154+
; VLEN128-NEXT: vsetvli a0, zero, e8, m8, ta, ma
155+
; VLEN128-NEXT: ret
156+
%vl = call iXLen @llvm.riscv.vsetvli.iXLen(iXLen 128, iXLen 0, iXLen 3)
157+
ret iXLen %vl
158+
}

0 commit comments

Comments
 (0)