diff --git a/llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp b/llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp index 4c57eecd8465dc..a96768240a9336 100644 --- a/llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp +++ b/llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp @@ -504,7 +504,7 @@ DemandedFields getDemanded(const MachineInstr &MI, const RISCVSubtarget *ST) { class VSETVLIInfo { struct AVLDef { // Every AVLDef should have a VNInfo. - unsigned ValNo; + const VNInfo *ValNo; Register DefReg; }; union { @@ -543,9 +543,9 @@ class VSETVLIInfo { void setUnknown() { State = Unknown; } bool isUnknown() const { return State == Unknown; } - void setAVLRegDef(unsigned ValNo, Register AVLReg) { - assert(AVLReg.isVirtual()); - AVLRegDef.ValNo = ValNo; + void setAVLRegDef(const VNInfo *VNInfo, Register AVLReg) { + assert(VNInfo && AVLReg.isVirtual()); + AVLRegDef.ValNo = VNInfo; AVLRegDef.DefReg = AVLReg; State = AVLIsReg; } @@ -571,7 +571,7 @@ class VSETVLIInfo { assert(hasAVLImm()); return AVLImm; } - unsigned getAVLValNo() const { + const VNInfo *getAVLVNInfo() const { assert(hasAVLReg()); return AVLRegDef.ValNo; } @@ -580,10 +580,8 @@ class VSETVLIInfo { // boundary slot. const MachineInstr *getAVLDefMI(const LiveIntervals *LIS) const { assert(hasAVLReg()); - const VNInfo *VNI = - LIS->getInterval(getAVLReg()).getValNumInfo(getAVLValNo()); - auto *MI = LIS->getInstructionFromIndex(VNI->def); - assert(!(VNI->isPHIDef() && MI)); + auto *MI = LIS->getInstructionFromIndex(getAVLVNInfo()->def); + assert(!(getAVLVNInfo()->isPHIDef() && MI)); return MI; } @@ -592,7 +590,7 @@ class VSETVLIInfo { if (Info.isUnknown()) setUnknown(); else if (Info.hasAVLReg()) - setAVLRegDef(Info.getAVLValNo(), Info.getAVLReg()); + setAVLRegDef(Info.getAVLVNInfo(), Info.getAVLReg()); else if (Info.hasAVLVLMAX()) setAVLVLMAX(); else if (Info.hasAVLIgnored()) @@ -631,7 +629,7 @@ class VSETVLIInfo { bool hasSameAVL(const VSETVLIInfo &Other) const { if (hasAVLReg() && Other.hasAVLReg()) - return getAVLValNo() == Other.getAVLValNo() && + return getAVLVNInfo()->id == Other.getAVLVNInfo()->id && getAVLReg() == Other.getAVLReg(); if (hasAVLImm() && Other.hasAVLImm()) @@ -935,7 +933,7 @@ RISCVInsertVSETVLI::getInfoForVSETVLI(const MachineInstr &MI) const { if (AVLReg == RISCV::X0) NewInfo.setAVLVLMAX(); else if (VNInfo *VNI = getVNInfoFromReg(AVLReg, MI, LIS)) - NewInfo.setAVLRegDef(VNI->id, AVLReg); + NewInfo.setAVLRegDef(VNI, AVLReg); else { assert(MI.getOperand(1).isUndef()); NewInfo.setAVLIgnored(); @@ -1011,7 +1009,7 @@ RISCVInsertVSETVLI::computeInfoForInstr(const MachineInstr &MI) const { else InstrInfo.setAVLImm(Imm); } else if (VNInfo *VNI = getVNInfoFromReg(VLOp.getReg(), MI, LIS)) { - InstrInfo.setAVLRegDef(VNI->id, VLOp.getReg()); + InstrInfo.setAVLRegDef(VNI, VLOp.getReg()); } else { assert(VLOp.isUndef()); InstrInfo.setAVLIgnored(); @@ -1262,7 +1260,7 @@ void RISCVInsertVSETVLI::transferAfter(VSETVLIInfo &Info, auto &LI = LIS->getInterval(MI.getOperand(1).getReg()); SlotIndex SI = LIS->getSlotIndexes()->getInstructionIndex(MI).getRegSlot(); VNInfo *VNI = LI.getVNInfoAt(SI); - Info.setAVLRegDef(VNI->id, MI.getOperand(1).getReg()); + Info.setAVLRegDef(VNI, MI.getOperand(1).getReg()); return; } @@ -1357,8 +1355,7 @@ bool RISCVInsertVSETVLI::needVSETVLIPHI(const VSETVLIInfo &Require, return true; // We need the AVL to have been produced by a PHI node in this basic block. - const VNInfo *Valno = LIS->getInterval(Require.getAVLReg()) - .getValNumInfo(Require.getAVLValNo()); + const VNInfo *Valno = Require.getAVLVNInfo(); if (!Valno->isPHIDef() || LIS->getMBBFromIndex(Valno->def) != &MBB) return true; @@ -1522,8 +1519,7 @@ void RISCVInsertVSETVLI::doPRE(MachineBasicBlock &MBB) { // we need to prove the value is available at the point we're going // to insert the vsetvli at. if (AvailableInfo.hasAVLReg()) { - const LiveInterval &LI = LIS->getInterval(AvailableInfo.getAVLReg()); - SlotIndex SI = LI.getValNumInfo(AvailableInfo.getAVLValNo())->def; + SlotIndex SI = AvailableInfo.getAVLVNInfo()->def; // This is an inline dominance check which covers the case of // UnavailablePred being the preheader of a loop. if (LIS->getMBBFromIndex(SI) != UnavailablePred)