Skip to content

Commit 4045d2c

Browse files
committed
[RISCV] Use separate VSETVLIInfo check for VL/VTYPE equality. NFC
In VSETVLIInfo we define == as structural equality, e.g. unknown == unknown and invalid == invalid. We need this to check if the information at a block's entry or exit has changed. However I think we may have been conflating it with the notion that the state of VL and VTYPE are the same, which isn't the case for two unknowns, and potentially in an upcoming patch where we don't know the value of an AVL register (see llvm#93796) This patch introduces a new method for checking that the VL and VTYPE are the same and switches it over where it would make a difference. This should be NFC for now since the two uses of == we're replacing either didn't compare two unknowns or checked for unknowns. But it's needed if we're to introduce the notion of an AVLReg with a nullptr ValNo, which will need this non-reflexive equality.
1 parent 836ca5b commit 4045d2c

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -732,6 +732,19 @@ class VSETVLIInfo {
732732
return hasCompatibleVTYPE(Used, Require);
733733
}
734734

735+
bool isKnownSame(const VSETVLIInfo &Other) const {
736+
if (!isValid() || !Other.isValid())
737+
return false;
738+
if (isUnknown() || Other.isUnknown())
739+
return false;
740+
if (SEWLMULRatioOnly || Other.SEWLMULRatioOnly)
741+
return false;
742+
return hasSameAVL(Other) && hasSameVTYPE(Other);
743+
}
744+
745+
// Whether or not two VSETVLIInfos are the same. Note that this does
746+
// not necessarily mean they have the same AVL or VTYPE. Use
747+
// isCompatible or isKnownSame for that instead.
735748
bool operator==(const VSETVLIInfo &Other) const {
736749
// Uninitialized is only equal to another Uninitialized.
737750
if (!isValid())
@@ -745,7 +758,13 @@ class VSETVLIInfo {
745758
if (Other.isUnknown())
746759
return isUnknown();
747760

748-
if (!hasSameAVL(Other))
761+
// If what we know about the AVL is different, then they aren't equal.
762+
if (State != Other.State)
763+
return false;
764+
if (hasAVLReg() && !(getAVLReg() == Other.getAVLReg() &&
765+
getAVLVNInfo() == Other.getAVLVNInfo()))
766+
return false;
767+
if (hasAVLImm() && getAVLImm() != Other.getAVLImm())
749768
return false;
750769

751770
// If the SEWLMULRatioOnly bits are different, then they aren't equal.
@@ -780,7 +799,7 @@ class VSETVLIInfo {
780799
return VSETVLIInfo::getUnknown();
781800

782801
// If we have an exact, match return this.
783-
if (*this == Other)
802+
if (isKnownSame(Other))
784803
return *this;
785804

786805
// Not an exact match, but maybe the AVL and VLMAX are the same. If so,
@@ -1375,7 +1394,7 @@ bool RISCVInsertVSETVLI::needVSETVLIPHI(const VSETVLIInfo &Require,
13751394
// We found a VSET(I)VLI make sure it matches the output of the
13761395
// predecessor block.
13771396
VSETVLIInfo DefInfo = getInfoForVSETVLI(*DefMI);
1378-
if (DefInfo != PBBExit)
1397+
if (!DefInfo.isKnownSame(PBBExit))
13791398
return true;
13801399

13811400
// Require has the same VL as PBBExit, so if the exit from the
@@ -1412,7 +1431,7 @@ void RISCVInsertVSETVLI::emitVSETVLIs(MachineBasicBlock &MBB) {
14121431

14131432
uint64_t TSFlags = MI.getDesc().TSFlags;
14141433
if (RISCVII::hasSEWOp(TSFlags)) {
1415-
if (PrevInfo != CurInfo) {
1434+
if (!PrevInfo.isKnownSame(CurInfo)) {
14161435
// If this is the first implicit state change, and the state change
14171436
// requested can be proven to produce the same register contents, we
14181437
// can skip emitting the actual state change and continue as if we

0 commit comments

Comments
 (0)