Skip to content

Commit 3e5f8fe

Browse files
committed
[RISCV] Add invariants that registers always have definitions. NFC
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.
1 parent 2cb97c7 commit 3e5f8fe

File tree

1 file changed

+23
-18
lines changed

1 file changed

+23
-18
lines changed

llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -198,19 +198,22 @@ static bool hasUndefinedMergeOp(const MachineInstr &MI,
198198
if (UseMO.getReg().isPhysical())
199199
return false;
200200

201-
if (MachineInstr *UseMI = MRI.getVRegDef(UseMO.getReg())) {
202-
if (UseMI->isImplicitDef())
203-
return true;
201+
MachineInstr *UseMI = MRI.getUniqueVRegDef(UseMO.getReg());
202+
assert(UseMI);
203+
if (UseMI->isImplicitDef())
204+
return true;
204205

205-
if (UseMI->isRegSequence()) {
206-
for (unsigned i = 1, e = UseMI->getNumOperands(); i < e; i += 2) {
207-
MachineInstr *SourceMI = MRI.getVRegDef(UseMI->getOperand(i).getReg());
208-
if (!SourceMI || !SourceMI->isImplicitDef())
209-
return false;
210-
}
211-
return true;
206+
if (UseMI->isRegSequence()) {
207+
for (unsigned i = 1, e = UseMI->getNumOperands(); i < e; i += 2) {
208+
MachineInstr *SourceMI =
209+
MRI.getUniqueVRegDef(UseMI->getOperand(i).getReg());
210+
assert(SourceMI);
211+
if (!SourceMI->isImplicitDef())
212+
return false;
212213
}
214+
return true;
213215
}
216+
214217
return false;
215218
}
216219

@@ -890,7 +893,7 @@ static VSETVLIInfo getInfoForVSETVLI(const MachineInstr &MI,
890893
if (AVLReg == RISCV::X0)
891894
NewInfo.setAVLVLMAX();
892895
else
893-
NewInfo.setAVLRegDef(MRI.getVRegDef(AVLReg), AVLReg);
896+
NewInfo.setAVLRegDef(MRI.getUniqueVRegDef(AVLReg), AVLReg);
894897
}
895898
NewInfo.setVTYPE(MI.getOperand(2).getImm());
896899

@@ -962,7 +965,8 @@ static VSETVLIInfo computeInfoForInstr(const MachineInstr &MI, uint64_t TSFlags,
962965
else
963966
InstrInfo.setAVLImm(Imm);
964967
} else {
965-
InstrInfo.setAVLRegDef(MRI->getVRegDef(VLOp.getReg()), VLOp.getReg());
968+
InstrInfo.setAVLRegDef(MRI->getUniqueVRegDef(VLOp.getReg()),
969+
VLOp.getReg());
966970
}
967971
} else {
968972
assert(isScalarExtractInstr(MI));
@@ -1235,7 +1239,7 @@ void RISCVInsertVSETVLI::transferAfter(VSETVLIInfo &Info,
12351239

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

13441348
// We need the PHI input to the be the output of a VSET(I)VLI.
1345-
MachineInstr *DefMI = MRI->getVRegDef(InReg);
1346-
if (!DefMI || !isVectorConfigInstr(*DefMI))
1349+
MachineInstr *DefMI = MRI->getUniqueVRegDef(InReg);
1350+
assert(DefMI);
1351+
if (!isVectorConfigInstr(*DefMI))
13471352
return true;
13481353

13491354
// We found a VSET(I)VLI make sure it matches the output of the
@@ -1403,7 +1408,8 @@ void RISCVInsertVSETVLI::emitVSETVLIs(MachineBasicBlock &MBB) {
14031408
MachineOperand &VLOp = MI.getOperand(getVLOpNum(MI));
14041409
if (VLOp.isReg()) {
14051410
Register Reg = VLOp.getReg();
1406-
MachineInstr *VLOpDef = MRI->getVRegDef(Reg);
1411+
MachineInstr *VLOpDef = MRI->getUniqueVRegDef(Reg);
1412+
assert(VLOpDef);
14071413

14081414
// Erase the AVL operand from the instruction.
14091415
VLOp.setReg(RISCV::NoRegister);
@@ -1413,8 +1419,7 @@ void RISCVInsertVSETVLI::emitVSETVLIs(MachineBasicBlock &MBB) {
14131419
// as an ADDI. However, the ADDI might not have been used in the
14141420
// vsetvli, or a vsetvli might not have been emitted, so it may be
14151421
// dead now.
1416-
if (VLOpDef && TII->isAddImmediate(*VLOpDef, Reg) &&
1417-
MRI->use_nodbg_empty(Reg))
1422+
if (TII->isAddImmediate(*VLOpDef, Reg) && MRI->use_nodbg_empty(Reg))
14181423
VLOpDef->eraseFromParent();
14191424
}
14201425
MI.addOperand(MachineOperand::CreateReg(RISCV::VL, /*isDef*/ false,

0 commit comments

Comments
 (0)