Skip to content

Commit 8296f06

Browse files
authored
[RISCV] Add invariants that registers always have definitions. NFC (#90587)
For vector merge operands, we check if it's a NoRegister beforehand so any other register type should have a definition. For VL operands, they don't get replaced with NoRegisters since they're scalar and should also always have a definition, even if it's an implicit_def. All the definitions at this stage should also be unique, this will change in #70549
1 parent 0d93b01 commit 8296f06

File tree

1 file changed

+24
-18
lines changed

1 file changed

+24
-18
lines changed

llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -194,19 +194,22 @@ static bool hasUndefinedMergeOp(const MachineInstr &MI,
194194
if (UseMO.getReg().isPhysical())
195195
return false;
196196

197-
if (MachineInstr *UseMI = MRI.getVRegDef(UseMO.getReg())) {
198-
if (UseMI->isImplicitDef())
199-
return true;
197+
MachineInstr *UseMI = MRI.getUniqueVRegDef(UseMO.getReg());
198+
assert(UseMI);
199+
if (UseMI->isImplicitDef())
200+
return true;
200201

201-
if (UseMI->isRegSequence()) {
202-
for (unsigned i = 1, e = UseMI->getNumOperands(); i < e; i += 2) {
203-
MachineInstr *SourceMI = MRI.getVRegDef(UseMI->getOperand(i).getReg());
204-
if (!SourceMI || !SourceMI->isImplicitDef())
205-
return false;
206-
}
207-
return true;
202+
if (UseMI->isRegSequence()) {
203+
for (unsigned i = 1, e = UseMI->getNumOperands(); i < e; i += 2) {
204+
MachineInstr *SourceMI =
205+
MRI.getUniqueVRegDef(UseMI->getOperand(i).getReg());
206+
assert(SourceMI);
207+
if (!SourceMI->isImplicitDef())
208+
return false;
208209
}
210+
return true;
209211
}
212+
210213
return false;
211214
}
212215

@@ -886,7 +889,7 @@ static VSETVLIInfo getInfoForVSETVLI(const MachineInstr &MI,
886889
if (AVLReg == RISCV::X0)
887890
NewInfo.setAVLVLMAX();
888891
else
889-
NewInfo.setAVLRegDef(MRI.getVRegDef(AVLReg), AVLReg);
892+
NewInfo.setAVLRegDef(MRI.getUniqueVRegDef(AVLReg), AVLReg);
890893
}
891894
NewInfo.setVTYPE(MI.getOperand(2).getImm());
892895

@@ -958,7 +961,8 @@ static VSETVLIInfo computeInfoForInstr(const MachineInstr &MI, uint64_t TSFlags,
958961
else
959962
InstrInfo.setAVLImm(Imm);
960963
} else {
961-
InstrInfo.setAVLRegDef(MRI->getVRegDef(VLOp.getReg()), VLOp.getReg());
964+
InstrInfo.setAVLRegDef(MRI->getUniqueVRegDef(VLOp.getReg()),
965+
VLOp.getReg());
962966
}
963967
} else {
964968
assert(isScalarExtractInstr(MI));
@@ -1231,7 +1235,7 @@ void RISCVInsertVSETVLI::transferAfter(VSETVLIInfo &Info,
12311235

12321236
if (RISCV::isFaultFirstLoad(MI)) {
12331237
// Update AVL to vl-output of the fault first load.
1234-
Info.setAVLRegDef(MRI->getVRegDef(MI.getOperand(1).getReg()),
1238+
Info.setAVLRegDef(MRI->getUniqueVRegDef(MI.getOperand(1).getReg()),
12351239
MI.getOperand(1).getReg());
12361240
return;
12371241
}
@@ -1338,8 +1342,9 @@ bool RISCVInsertVSETVLI::needVSETVLIPHI(const VSETVLIInfo &Require,
13381342
const VSETVLIInfo &PBBExit = BlockInfo[PBB->getNumber()].Exit;
13391343

13401344
// We need the PHI input to the be the output of a VSET(I)VLI.
1341-
MachineInstr *DefMI = MRI->getVRegDef(InReg);
1342-
if (!DefMI || !isVectorConfigInstr(*DefMI))
1345+
MachineInstr *DefMI = MRI->getUniqueVRegDef(InReg);
1346+
assert(DefMI);
1347+
if (!isVectorConfigInstr(*DefMI))
13431348
return true;
13441349

13451350
// We found a VSET(I)VLI make sure it matches the output of the
@@ -1399,7 +1404,8 @@ void RISCVInsertVSETVLI::emitVSETVLIs(MachineBasicBlock &MBB) {
13991404
MachineOperand &VLOp = MI.getOperand(getVLOpNum(MI));
14001405
if (VLOp.isReg()) {
14011406
Register Reg = VLOp.getReg();
1402-
MachineInstr *VLOpDef = MRI->getVRegDef(Reg);
1407+
MachineInstr *VLOpDef = MRI->getUniqueVRegDef(Reg);
1408+
assert(VLOpDef);
14031409

14041410
// Erase the AVL operand from the instruction.
14051411
VLOp.setReg(RISCV::NoRegister);
@@ -1409,8 +1415,7 @@ void RISCVInsertVSETVLI::emitVSETVLIs(MachineBasicBlock &MBB) {
14091415
// as an ADDI. However, the ADDI might not have been used in the
14101416
// vsetvli, or a vsetvli might not have been emitted, so it may be
14111417
// dead now.
1412-
if (VLOpDef && TII->isAddImmediate(*VLOpDef, Reg) &&
1413-
MRI->use_nodbg_empty(Reg))
1418+
if (TII->isAddImmediate(*VLOpDef, Reg) && MRI->use_nodbg_empty(Reg))
14141419
VLOpDef->eraseFromParent();
14151420
}
14161421
MI.addOperand(MachineOperand::CreateReg(RISCV::VL, /*isDef*/ false,
@@ -1682,6 +1687,7 @@ void RISCVInsertVSETVLI::insertReadVL(MachineBasicBlock &MBB) {
16821687
MachineInstr &MI = *I++;
16831688
if (RISCV::isFaultFirstLoad(MI)) {
16841689
Register VLOutput = MI.getOperand(1).getReg();
1690+
assert(VLOutput.isVirtual());
16851691
if (!MRI->use_nodbg_empty(VLOutput))
16861692
BuildMI(MBB, I, MI.getDebugLoc(), TII->get(RISCV::PseudoReadVL),
16871693
VLOutput);

0 commit comments

Comments
 (0)