[llvm] 9ae2177 - [RISCV] Handle undef AVLs in RISCVInsertVSETVLI
Luke Lau via llvm-commits
llvm-commits at lists.llvm.org
Wed May 15 11:46:44 PDT 2024
Author: Luke Lau
Date: 2024-05-16T02:46:31+08:00
New Revision: 9ae2177843f681c70ad89506155a2cb83eeebfd4
URL: https://github.com/llvm/llvm-project/commit/9ae2177843f681c70ad89506155a2cb83eeebfd4
DIFF: https://github.com/llvm/llvm-project/commit/9ae2177843f681c70ad89506155a2cb83eeebfd4.diff
LOG: [RISCV] Handle undef AVLs in RISCVInsertVSETVLI
Before #91440 a VSETVLIInfo would have had an IMPLICIT_DEF defining
instruction, but now we look up a VNInfo which doesn't exist, which
triggers an assertion failure. Mark these undef AVLs as AVLIsIgnored.
Added:
Modified:
llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp
llvm/test/CodeGen/RISCV/rvv/vsetvli-insert.ll
Removed:
################################################################################
diff --git a/llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp b/llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp
index 1c815424bdfa6..363007d7b68b1 100644
--- a/llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp
+++ b/llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp
@@ -48,15 +48,13 @@ static cl::opt<bool> DisableInsertVSETVLPHIOpt(
namespace {
/// Given a virtual register \p Reg, return the corresponding VNInfo for it.
-/// This should never return nullptr.
+/// This will return nullptr if the virtual register is an implicit_def.
static VNInfo *getVNInfoFromReg(Register Reg, const MachineInstr &MI,
const LiveIntervals *LIS) {
assert(Reg.isVirtual());
auto &LI = LIS->getInterval(Reg);
SlotIndex SI = LIS->getSlotIndexes()->getInstructionIndex(MI);
- VNInfo *VNI = LI.getVNInfoBefore(SI);
- assert(VNI);
- return VNI;
+ return LI.getVNInfoBefore(SI);
}
static unsigned getVLOpNum(const MachineInstr &MI) {
@@ -894,8 +892,12 @@ static VSETVLIInfo getInfoForVSETVLI(const MachineInstr &MI,
"Can't handle X0, X0 vsetvli yet");
if (AVLReg == RISCV::X0)
NewInfo.setAVLVLMAX();
- else
- NewInfo.setAVLRegDef(getVNInfoFromReg(AVLReg, MI, LIS), AVLReg);
+ else if (VNInfo *VNI = getVNInfoFromReg(AVLReg, MI, LIS))
+ NewInfo.setAVLRegDef(VNI, AVLReg);
+ else {
+ assert(MI.getOperand(1).isUndef());
+ NewInfo.setAVLIgnored();
+ }
}
NewInfo.setVTYPE(MI.getOperand(2).getImm());
@@ -966,9 +968,11 @@ static VSETVLIInfo computeInfoForInstr(const MachineInstr &MI, uint64_t TSFlags,
}
else
InstrInfo.setAVLImm(Imm);
+ } else if (VNInfo *VNI = getVNInfoFromReg(VLOp.getReg(), MI, LIS)) {
+ InstrInfo.setAVLRegDef(VNI, VLOp.getReg());
} else {
- InstrInfo.setAVLRegDef(getVNInfoFromReg(VLOp.getReg(), MI, LIS),
- VLOp.getReg());
+ assert(VLOp.isUndef());
+ InstrInfo.setAVLIgnored();
}
} else {
assert(isScalarExtractInstr(MI));
diff --git a/llvm/test/CodeGen/RISCV/rvv/vsetvli-insert.ll b/llvm/test/CodeGen/RISCV/rvv/vsetvli-insert.ll
index 12bb4d27b0f97..da0c1cfb50097 100644
--- a/llvm/test/CodeGen/RISCV/rvv/vsetvli-insert.ll
+++ b/llvm/test/CodeGen/RISCV/rvv/vsetvli-insert.ll
@@ -699,3 +699,27 @@ declare <vscale x 2 x i1> @llvm.riscv.vmsgt.nxv2i32.i32.i64(<vscale x 2 x i32>,
declare <vscale x 2 x i1> @llvm.riscv.vmor.nxv2i1.i64(<vscale x 2 x i1>, <vscale x 2 x i1>, i64)
declare void @llvm.riscv.vse.mask.nxv2i32.i64(<vscale x 2 x i32>, ptr nocapture, <vscale x 2 x i1>, i64)
declare void @llvm.riscv.vse.nxv2i32.i64(<vscale x 2 x i32>, ptr nocapture, i64)
+
+define <vscale x 2 x i32> @avl_undef1(<vscale x 2 x i32>, <vscale x 2 x i32>, <vscale x 2 x i32>) {
+; CHECK-LABEL: avl_undef1:
+; CHECK: # %bb.0:
+; CHECK-NEXT: vsetivli zero, 1, e32, m1, tu, ma
+; CHECK-NEXT: vadd.vv v8, v9, v10
+; CHECK-NEXT: ret
+ %a = call <vscale x 2 x i32> @llvm.riscv.vadd.nxv2i32.nxv2i32(
+ <vscale x 2 x i32> %0,
+ <vscale x 2 x i32> %1,
+ <vscale x 2 x i32> %2,
+ i64 undef
+ )
+ ret <vscale x 2 x i32> %a
+}
+
+define i64 @avl_undef2() {
+; CHECK-LABEL: avl_undef2:
+; CHECK: # %bb.0:
+; CHECK-NEXT: vsetvli a0, a0, e32, mf2, ta, ma
+; CHECK-NEXT: ret
+ %1 = tail call i64 @llvm.riscv.vsetvli(i64 poison, i64 2, i64 7)
+ ret i64 %1
+}
More information about the llvm-commits
mailing list