Skip to content

Commit

Permalink
[RISCV] Use x0 in vsetvli when avl is equal to vlmax.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jacquesguan committed Jul 31, 2023
1 parent 75f770a commit b7408eb
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
6 changes: 6 additions & 0 deletions llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,12 @@ void RISCVDAGToDAGISel::selectVSETVLI(SDNode *Node) {

SDValue VLOperand;
unsigned Opcode = RISCV::PseudoVSETVLI;
if (auto *C = dyn_cast<ConstantSDNode>(Node->getOperand(1))) {
const unsigned VLEN = Subtarget->getRealMinVLen();
if (VLEN == Subtarget->getRealMaxVLen())
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;
Expand Down
25 changes: 23 additions & 2 deletions llvm/test/CodeGen/RISCV/rvv/vsetvli-intrinsics.ll
Original file line number Diff line number Diff line change
@@ -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,VLENUNKNOWN
; 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,VLENUNKNOWN
; 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)
Expand Down Expand Up @@ -135,3 +141,18 @@ define iXLen @test_vsetvli_negone_e8m1(iXLen %avl) nounwind {
%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 {
; VLENUNKNOWN-LABEL: test_vsetvli_eqvlmax_e8m8:
; VLENUNKNOWN: # %bb.0:
; VLENUNKNOWN-NEXT: li a0, 128
; VLENUNKNOWN-NEXT: vsetvli a0, a0, e8, m8, ta, ma
; VLENUNKNOWN-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
}

0 comments on commit b7408eb

Please sign in to comment.