Skip to content

Commit

Permalink
Revert "[RISCV] Store only VNInfo val no in VSETVLIInfo. NFC"
Browse files Browse the repository at this point in the history
As noted in
llvm#93796 (comment),
a better way to teach RISCVInsertVSETVLI to work without LiveIntervals
is to set VNInfo to nullptr and teach the various methods to handle it.
We should try that approach first, so we no longer need this pre-commit
patch.

This reverts commit 4b4d366.
  • Loading branch information
lukel97 committed Jun 3, 2024
1 parent 16c925a commit 83de21d
Showing 1 changed file with 14 additions and 18 deletions.
32 changes: 14 additions & 18 deletions llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
}
Expand All @@ -571,7 +571,7 @@ class VSETVLIInfo {
assert(hasAVLImm());
return AVLImm;
}
unsigned getAVLValNo() const {
const VNInfo *getAVLVNInfo() const {
assert(hasAVLReg());
return AVLRegDef.ValNo;
}
Expand All @@ -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;
}

Expand All @@ -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())
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 83de21d

Please sign in to comment.