Skip to content

Commit 4ed7160

Browse files
committed
Use const reference for getAVLDefMI and remove some useless assert
1 parent a5074f5 commit 4ed7160

File tree

1 file changed

+17
-19
lines changed

1 file changed

+17
-19
lines changed

llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -522,17 +522,17 @@ class VSETVLIInfo {
522522
assert(hasAVLImm());
523523
return AVLImm;
524524
}
525-
const MachineInstr *getAVLDefMI() const {
525+
const MachineInstr &getAVLDefMI() const {
526526
assert(hasAVLReg() && AVLRegDef.DefMI);
527-
return AVLRegDef.DefMI;
527+
return *AVLRegDef.DefMI;
528528
}
529529

530530
void setAVL(VSETVLIInfo Info) {
531531
assert(Info.isValid());
532532
if (Info.isUnknown())
533533
setUnknown();
534534
else if (Info.hasAVLReg())
535-
setAVLRegDef(Info.getAVLDefMI(), Info.getAVLReg());
535+
setAVLRegDef(&Info.getAVLDefMI(), Info.getAVLReg());
536536
else if (Info.hasAVLVLMAX())
537537
setAVLVLMAX();
538538
else if (Info.hasAVLIgnored())
@@ -551,10 +551,8 @@ class VSETVLIInfo {
551551
bool hasNonZeroAVL() const {
552552
if (hasAVLImm())
553553
return getAVLImm() > 0;
554-
if (hasAVLReg()) {
555-
const MachineInstr *MI = getAVLDefMI();
556-
return isNonZeroLoadImmediate(*MI);
557-
}
554+
if (hasAVLReg())
555+
return isNonZeroLoadImmediate(getAVLDefMI());
558556
if (hasAVLVLMAX())
559557
return true;
560558
if (hasAVLIgnored())
@@ -570,7 +568,7 @@ class VSETVLIInfo {
570568

571569
bool hasSameAVL(const VSETVLIInfo &Other) const {
572570
if (hasAVLReg() && Other.hasAVLReg())
573-
return getAVLDefMI()->isIdenticalTo(*Other.getAVLDefMI());
571+
return getAVLDefMI().isIdenticalTo(Other.getAVLDefMI());
574572

575573
if (hasAVLImm() && Other.hasAVLImm())
576574
return getAVLImm() == Other.getAVLImm();
@@ -984,9 +982,9 @@ static VSETVLIInfo computeInfoForInstr(const MachineInstr &MI, uint64_t TSFlags,
984982
// register AVLs to avoid extending live ranges without being sure we can
985983
// kill the original source reg entirely.
986984
if (InstrInfo.hasAVLReg()) {
987-
const MachineInstr *DefMI = InstrInfo.getAVLDefMI();
988-
if (isVectorConfigInstr(*DefMI)) {
989-
VSETVLIInfo DefInstrInfo = getInfoForVSETVLI(*DefMI, *MRI);
985+
const MachineInstr &DefMI = InstrInfo.getAVLDefMI();
986+
if (isVectorConfigInstr(DefMI)) {
987+
VSETVLIInfo DefInstrInfo = getInfoForVSETVLI(DefMI, *MRI);
990988
if (DefInstrInfo.hasSameVLMAX(InstrInfo) &&
991989
(DefInstrInfo.hasAVLImm() || DefInstrInfo.hasAVLVLMAX()))
992990
InstrInfo.setAVL(DefInstrInfo);
@@ -1024,9 +1022,9 @@ void RISCVInsertVSETVLI::insertVSETVLI(MachineBasicBlock &MBB,
10241022
// it has the same VLMAX we want and the last VL/VTYPE we observed is the
10251023
// same, we can use the X0, X0 form.
10261024
if (Info.hasSameVLMAX(PrevInfo) && Info.hasAVLReg()) {
1027-
const MachineInstr *DefMI = Info.getAVLDefMI();
1028-
if (isVectorConfigInstr(*DefMI)) {
1029-
VSETVLIInfo DefInfo = getInfoForVSETVLI(*DefMI, *MRI);
1025+
const MachineInstr &DefMI = Info.getAVLDefMI();
1026+
if (isVectorConfigInstr(DefMI)) {
1027+
VSETVLIInfo DefInfo = getInfoForVSETVLI(DefMI, *MRI);
10301028
if (DefInfo.hasSameAVL(PrevInfo) && DefInfo.hasSameVLMAX(PrevInfo)) {
10311029
BuildMI(MBB, InsertPt, DL, TII->get(RISCV::PseudoVSETVLIX0))
10321030
.addReg(RISCV::X0, RegState::Define | RegState::Dead)
@@ -1142,9 +1140,9 @@ bool RISCVInsertVSETVLI::needVSETVLI(const MachineInstr &MI,
11421140
// and the last VL/VTYPE we observed is the same, we don't need a
11431141
// VSETVLI here.
11441142
if (Require.hasAVLReg() && CurInfo.hasCompatibleVTYPE(Used, Require)) {
1145-
const MachineInstr *DefMI = Require.getAVLDefMI();
1146-
if (DefMI && isVectorConfigInstr(*DefMI)) {
1147-
VSETVLIInfo DefInfo = getInfoForVSETVLI(*DefMI, *MRI);
1143+
const MachineInstr &DefMI = Require.getAVLDefMI();
1144+
if (isVectorConfigInstr(DefMI)) {
1145+
VSETVLIInfo DefInfo = getInfoForVSETVLI(DefMI, *MRI);
11481146
if (DefInfo.hasSameAVL(CurInfo) && DefInfo.hasSameVLMAX(CurInfo))
11491147
return false;
11501148
}
@@ -1332,7 +1330,7 @@ bool RISCVInsertVSETVLI::needVSETVLIPHI(const VSETVLIInfo &Require,
13321330
return true;
13331331

13341332
// We need the AVL to be produce by a PHI node in this basic block.
1335-
const MachineInstr *PHI = Require.getAVLDefMI();
1333+
const MachineInstr *PHI = &Require.getAVLDefMI();
13361334
if (PHI->getOpcode() != RISCV::PHI || PHI->getParent() != &MBB)
13371335
return true;
13381336

@@ -1503,7 +1501,7 @@ void RISCVInsertVSETVLI::doPRE(MachineBasicBlock &MBB) {
15031501
// we need to prove the value is available at the point we're going
15041502
// to insert the vsetvli at.
15051503
if (AvailableInfo.hasAVLReg()) {
1506-
const MachineInstr *AVLDefMI = AvailableInfo.getAVLDefMI();
1504+
const MachineInstr *AVLDefMI = &AvailableInfo.getAVLDefMI();
15071505
// This is an inline dominance check which covers the case of
15081506
// UnavailablePred being the preheader of a loop.
15091507
if (AVLDefMI->getParent() != UnavailablePred)

0 commit comments

Comments
 (0)