Skip to content

Commit a5074f5

Browse files
committed
Store both AVLReg and AVLRegDefMI
1 parent 2182cf9 commit a5074f5

File tree

1 file changed

+30
-29
lines changed

1 file changed

+30
-29
lines changed

llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -454,14 +454,18 @@ DemandedFields getDemanded(const MachineInstr &MI,
454454
/// Defines the abstract state with which the forward dataflow models the
455455
/// values of the VL and VTYPE registers after insertion.
456456
class VSETVLIInfo {
457+
struct AVLDef {
458+
const MachineInstr *DefMI;
459+
Register DefReg;
460+
};
457461
union {
458-
const MachineInstr *AVLDefMI;
462+
AVLDef AVLRegDef;
459463
unsigned AVLImm;
460464
};
461465

462466
enum : uint8_t {
463467
Uninitialized,
464-
AVLIsDefMI,
468+
AVLIsReg,
465469
AVLIsImm,
466470
AVLIsVLMAX,
467471
AVLIsIgnored,
@@ -490,10 +494,11 @@ class VSETVLIInfo {
490494
void setUnknown() { State = Unknown; }
491495
bool isUnknown() const { return State == Unknown; }
492496

493-
void setAVLDefMI(const MachineInstr *DefMI) {
494-
assert(DefMI);
495-
AVLDefMI = DefMI;
496-
State = AVLIsDefMI;
497+
void setAVLRegDef(const MachineInstr *DefMI, Register AVLReg) {
498+
assert(DefMI && AVLReg.isVirtual());
499+
AVLRegDef.DefMI = DefMI;
500+
AVLRegDef.DefReg = AVLReg;
501+
State = AVLIsReg;
497502
}
498503

499504
void setAVLImm(unsigned Imm) {
@@ -506,29 +511,28 @@ class VSETVLIInfo {
506511
void setAVLIgnored() { State = AVLIsIgnored; }
507512

508513
bool hasAVLImm() const { return State == AVLIsImm; }
509-
bool hasAVLDefMI() const { return State == AVLIsDefMI; }
514+
bool hasAVLReg() const { return State == AVLIsReg; }
510515
bool hasAVLVLMAX() const { return State == AVLIsVLMAX; }
511516
bool hasAVLIgnored() const { return State == AVLIsIgnored; }
512517
Register getAVLReg() const {
513-
assert(hasAVLDefMI());
514-
return AVLDefMI->getOperand(0).getReg();
518+
assert(hasAVLReg() && AVLRegDef.DefReg.isVirtual());
519+
return AVLRegDef.DefReg;
515520
}
516521
unsigned getAVLImm() const {
517522
assert(hasAVLImm());
518523
return AVLImm;
519524
}
520-
521525
const MachineInstr *getAVLDefMI() const {
522-
assert(AVLDefMI);
523-
return AVLDefMI;
526+
assert(hasAVLReg() && AVLRegDef.DefMI);
527+
return AVLRegDef.DefMI;
524528
}
525529

526530
void setAVL(VSETVLIInfo Info) {
527531
assert(Info.isValid());
528532
if (Info.isUnknown())
529533
setUnknown();
530-
else if (Info.hasAVLDefMI())
531-
setAVLDefMI(Info.getAVLDefMI());
534+
else if (Info.hasAVLReg())
535+
setAVLRegDef(Info.getAVLDefMI(), Info.getAVLReg());
532536
else if (Info.hasAVLVLMAX())
533537
setAVLVLMAX();
534538
else if (Info.hasAVLIgnored())
@@ -547,9 +551,8 @@ class VSETVLIInfo {
547551
bool hasNonZeroAVL() const {
548552
if (hasAVLImm())
549553
return getAVLImm() > 0;
550-
if (hasAVLDefMI()) {
554+
if (hasAVLReg()) {
551555
const MachineInstr *MI = getAVLDefMI();
552-
assert(MI);
553556
return isNonZeroLoadImmediate(*MI);
554557
}
555558
if (hasAVLVLMAX())
@@ -566,7 +569,7 @@ class VSETVLIInfo {
566569
}
567570

568571
bool hasSameAVL(const VSETVLIInfo &Other) const {
569-
if (hasAVLDefMI() && Other.hasAVLDefMI())
572+
if (hasAVLReg() && Other.hasAVLReg())
570573
return getAVLDefMI()->isIdenticalTo(*Other.getAVLDefMI());
571574

572575
if (hasAVLImm() && Other.hasAVLImm())
@@ -747,7 +750,7 @@ class VSETVLIInfo {
747750
OS << "Uninitialized";
748751
if (isUnknown())
749752
OS << "unknown";
750-
if (hasAVLDefMI())
753+
if (hasAVLReg())
751754
OS << "AVLReg=" << (unsigned)getAVLReg();
752755
if (hasAVLImm())
753756
OS << "AVLImm=" << (unsigned)AVLImm;
@@ -888,7 +891,7 @@ static VSETVLIInfo getInfoForVSETVLI(const MachineInstr &MI,
888891
if (AVLReg == RISCV::X0)
889892
NewInfo.setAVLVLMAX();
890893
else
891-
NewInfo.setAVLDefMI(MRI.getVRegDef(AVLReg));
894+
NewInfo.setAVLRegDef(MRI.getVRegDef(AVLReg), AVLReg);
892895
}
893896
NewInfo.setVTYPE(MI.getOperand(2).getImm());
894897

@@ -960,7 +963,7 @@ static VSETVLIInfo computeInfoForInstr(const MachineInstr &MI, uint64_t TSFlags,
960963
else
961964
InstrInfo.setAVLImm(Imm);
962965
} else {
963-
InstrInfo.setAVLDefMI(MRI->getVRegDef(VLOp.getReg()));
966+
InstrInfo.setAVLRegDef(MRI->getVRegDef(VLOp.getReg()), VLOp.getReg());
964967
}
965968
} else {
966969
assert(isScalarExtractInstr(MI));
@@ -980,7 +983,7 @@ static VSETVLIInfo computeInfoForInstr(const MachineInstr &MI, uint64_t TSFlags,
980983
// AVL operand with the AVL of the defining vsetvli. We avoid general
981984
// register AVLs to avoid extending live ranges without being sure we can
982985
// kill the original source reg entirely.
983-
if (InstrInfo.hasAVLDefMI()) {
986+
if (InstrInfo.hasAVLReg()) {
984987
const MachineInstr *DefMI = InstrInfo.getAVLDefMI();
985988
if (isVectorConfigInstr(*DefMI)) {
986989
VSETVLIInfo DefInstrInfo = getInfoForVSETVLI(*DefMI, *MRI);
@@ -1020,9 +1023,8 @@ void RISCVInsertVSETVLI::insertVSETVLI(MachineBasicBlock &MBB,
10201023
// If our AVL is a virtual register, it might be defined by a VSET(I)VLI. If
10211024
// it has the same VLMAX we want and the last VL/VTYPE we observed is the
10221025
// same, we can use the X0, X0 form.
1023-
if (Info.hasSameVLMAX(PrevInfo) && Info.hasAVLDefMI()) {
1026+
if (Info.hasSameVLMAX(PrevInfo) && Info.hasAVLReg()) {
10241027
const MachineInstr *DefMI = Info.getAVLDefMI();
1025-
assert(DefMI);
10261028
if (isVectorConfigInstr(*DefMI)) {
10271029
VSETVLIInfo DefInfo = getInfoForVSETVLI(*DefMI, *MRI);
10281030
if (DefInfo.hasSameAVL(PrevInfo) && DefInfo.hasSameVLMAX(PrevInfo)) {
@@ -1139,9 +1141,8 @@ bool RISCVInsertVSETVLI::needVSETVLI(const MachineInstr &MI,
11391141
// it might be defined by a VSET(I)VLI. If it has the same VLMAX we need
11401142
// and the last VL/VTYPE we observed is the same, we don't need a
11411143
// VSETVLI here.
1142-
if (Require.hasAVLDefMI() && CurInfo.hasCompatibleVTYPE(Used, Require)) {
1144+
if (Require.hasAVLReg() && CurInfo.hasCompatibleVTYPE(Used, Require)) {
11431145
const MachineInstr *DefMI = Require.getAVLDefMI();
1144-
assert(DefMI);
11451146
if (DefMI && isVectorConfigInstr(*DefMI)) {
11461147
VSETVLIInfo DefInfo = getInfoForVSETVLI(*DefMI, *MRI);
11471148
if (DefInfo.hasSameAVL(CurInfo) && DefInfo.hasSameVLMAX(CurInfo))
@@ -1235,7 +1236,8 @@ void RISCVInsertVSETVLI::transferAfter(VSETVLIInfo &Info,
12351236

12361237
if (RISCV::isFaultFirstLoad(MI)) {
12371238
// Update AVL to vl-output of the fault first load.
1238-
Info.setAVLDefMI(MRI->getVRegDef(MI.getOperand(1).getReg()));
1239+
Info.setAVLRegDef(MRI->getVRegDef(MI.getOperand(1).getReg()),
1240+
MI.getOperand(1).getReg());
12391241
return;
12401242
}
12411243

@@ -1326,7 +1328,7 @@ bool RISCVInsertVSETVLI::needVSETVLIPHI(const VSETVLIInfo &Require,
13261328
if (DisableInsertVSETVLPHIOpt)
13271329
return true;
13281330

1329-
if (!Require.hasAVLDefMI())
1331+
if (!Require.hasAVLReg())
13301332
return true;
13311333

13321334
// We need the AVL to be produce by a PHI node in this basic block.
@@ -1500,9 +1502,8 @@ void RISCVInsertVSETVLI::doPRE(MachineBasicBlock &MBB) {
15001502
// If the AVL value is a register (other than our VLMAX sentinel),
15011503
// we need to prove the value is available at the point we're going
15021504
// to insert the vsetvli at.
1503-
if (AvailableInfo.hasAVLDefMI()) {
1505+
if (AvailableInfo.hasAVLReg()) {
15041506
const MachineInstr *AVLDefMI = AvailableInfo.getAVLDefMI();
1505-
assert(AVLDefMI);
15061507
// This is an inline dominance check which covers the case of
15071508
// UnavailablePred being the preheader of a loop.
15081509
if (AVLDefMI->getParent() != UnavailablePred)

0 commit comments

Comments
 (0)