Skip to content

Commit

Permalink
[RISCV] Handle undef AVLs in RISCVInsertVSETVLI
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
lukel97 committed May 15, 2024
1 parent 2c54bf4 commit 9ae2177
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 8 deletions.
20 changes: 12 additions & 8 deletions llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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());

Expand Down Expand Up @@ -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));
Expand Down
24 changes: 24 additions & 0 deletions llvm/test/CodeGen/RISCV/rvv/vsetvli-insert.ll
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 9ae2177

Please sign in to comment.