Skip to content

Commit 9ae2177

Browse files
committed
[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.
1 parent 2c54bf4 commit 9ae2177

File tree

2 files changed

+36
-8
lines changed

2 files changed

+36
-8
lines changed

llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,13 @@ static cl::opt<bool> DisableInsertVSETVLPHIOpt(
4848
namespace {
4949

5050
/// Given a virtual register \p Reg, return the corresponding VNInfo for it.
51-
/// This should never return nullptr.
51+
/// This will return nullptr if the virtual register is an implicit_def.
5252
static VNInfo *getVNInfoFromReg(Register Reg, const MachineInstr &MI,
5353
const LiveIntervals *LIS) {
5454
assert(Reg.isVirtual());
5555
auto &LI = LIS->getInterval(Reg);
5656
SlotIndex SI = LIS->getSlotIndexes()->getInstructionIndex(MI);
57-
VNInfo *VNI = LI.getVNInfoBefore(SI);
58-
assert(VNI);
59-
return VNI;
57+
return LI.getVNInfoBefore(SI);
6058
}
6159

6260
static unsigned getVLOpNum(const MachineInstr &MI) {
@@ -894,8 +892,12 @@ static VSETVLIInfo getInfoForVSETVLI(const MachineInstr &MI,
894892
"Can't handle X0, X0 vsetvli yet");
895893
if (AVLReg == RISCV::X0)
896894
NewInfo.setAVLVLMAX();
897-
else
898-
NewInfo.setAVLRegDef(getVNInfoFromReg(AVLReg, MI, LIS), AVLReg);
895+
else if (VNInfo *VNI = getVNInfoFromReg(AVLReg, MI, LIS))
896+
NewInfo.setAVLRegDef(VNI, AVLReg);
897+
else {
898+
assert(MI.getOperand(1).isUndef());
899+
NewInfo.setAVLIgnored();
900+
}
899901
}
900902
NewInfo.setVTYPE(MI.getOperand(2).getImm());
901903

@@ -966,9 +968,11 @@ static VSETVLIInfo computeInfoForInstr(const MachineInstr &MI, uint64_t TSFlags,
966968
}
967969
else
968970
InstrInfo.setAVLImm(Imm);
971+
} else if (VNInfo *VNI = getVNInfoFromReg(VLOp.getReg(), MI, LIS)) {
972+
InstrInfo.setAVLRegDef(VNI, VLOp.getReg());
969973
} else {
970-
InstrInfo.setAVLRegDef(getVNInfoFromReg(VLOp.getReg(), MI, LIS),
971-
VLOp.getReg());
974+
assert(VLOp.isUndef());
975+
InstrInfo.setAVLIgnored();
972976
}
973977
} else {
974978
assert(isScalarExtractInstr(MI));

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -699,3 +699,27 @@ declare <vscale x 2 x i1> @llvm.riscv.vmsgt.nxv2i32.i32.i64(<vscale x 2 x i32>,
699699
declare <vscale x 2 x i1> @llvm.riscv.vmor.nxv2i1.i64(<vscale x 2 x i1>, <vscale x 2 x i1>, i64)
700700
declare void @llvm.riscv.vse.mask.nxv2i32.i64(<vscale x 2 x i32>, ptr nocapture, <vscale x 2 x i1>, i64)
701701
declare void @llvm.riscv.vse.nxv2i32.i64(<vscale x 2 x i32>, ptr nocapture, i64)
702+
703+
define <vscale x 2 x i32> @avl_undef1(<vscale x 2 x i32>, <vscale x 2 x i32>, <vscale x 2 x i32>) {
704+
; CHECK-LABEL: avl_undef1:
705+
; CHECK: # %bb.0:
706+
; CHECK-NEXT: vsetivli zero, 1, e32, m1, tu, ma
707+
; CHECK-NEXT: vadd.vv v8, v9, v10
708+
; CHECK-NEXT: ret
709+
%a = call <vscale x 2 x i32> @llvm.riscv.vadd.nxv2i32.nxv2i32(
710+
<vscale x 2 x i32> %0,
711+
<vscale x 2 x i32> %1,
712+
<vscale x 2 x i32> %2,
713+
i64 undef
714+
)
715+
ret <vscale x 2 x i32> %a
716+
}
717+
718+
define i64 @avl_undef2() {
719+
; CHECK-LABEL: avl_undef2:
720+
; CHECK: # %bb.0:
721+
; CHECK-NEXT: vsetvli a0, a0, e32, mf2, ta, ma
722+
; CHECK-NEXT: ret
723+
%1 = tail call i64 @llvm.riscv.vsetvli(i64 poison, i64 2, i64 7)
724+
ret i64 %1
725+
}

0 commit comments

Comments
 (0)