Skip to content

Commit d18cdc9

Browse files
authored
[RISCVInsertVSETVLI] Don't allow getSEW/getLMUL to be called for hasSEWLMULRatioOnly(). NFC (llvm#171554)
Refactor some logic in transferBefore to handle hasSEWLMULRatioOnly() before calling getSEW/getLMUL. Update adjustIncoming to use getSEWLMULRatio(). Update the interface of RISCVVType::getSameRatioLMUL to take the ratio instead of SEW and LMUL. Update the few other callers to call RISCVVType::getSEWLMULRatio first.
1 parent fcdac81 commit d18cdc9

File tree

5 files changed

+37
-32
lines changed

5 files changed

+37
-32
lines changed

llvm/include/llvm/TargetParser/RISCVTargetParser.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,7 @@ LLVM_ABI void printXSfmmVType(unsigned VType, raw_ostream &OS);
165165

166166
LLVM_ABI unsigned getSEWLMULRatio(unsigned SEW, VLMUL VLMul);
167167

168-
LLVM_ABI std::optional<VLMUL> getSameRatioLMUL(unsigned SEW, VLMUL VLMUL,
169-
unsigned EEW);
168+
LLVM_ABI std::optional<VLMUL> getSameRatioLMUL(unsigned Ratio, unsigned EEW);
170169
} // namespace RISCVVType
171170

172171
} // namespace llvm

llvm/lib/Target/RISCV/MCA/RISCVCustomBehaviour.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,8 @@ getEEWAndEMUL(unsigned Opcode, RISCVVType::VLMUL LMUL, uint8_t SEW) {
215215
llvm_unreachable("Could not determine EEW from Opcode");
216216
}
217217

218-
auto EMUL = RISCVVType::getSameRatioLMUL(SEW, LMUL, EEW);
218+
auto EMUL =
219+
RISCVVType::getSameRatioLMUL(RISCVVType::getSEWLMULRatio(SEW, LMUL), EEW);
219220
if (!EEW)
220221
llvm_unreachable("Invalid SEW or LMUL for new ratio");
221222
return std::make_pair(EEW, *EMUL);

llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -607,13 +607,15 @@ class VSETVLIInfo {
607607
}
608608
}
609609

610+
bool hasSEWLMULRatioOnly() const { return SEWLMULRatioOnly; }
611+
610612
unsigned getSEW() const {
611-
assert(isValid() && !isUnknown() &&
613+
assert(isValid() && !isUnknown() && !hasSEWLMULRatioOnly() &&
612614
"Can't use VTYPE for uninitialized or unknown");
613615
return SEW;
614616
}
615617
RISCVVType::VLMUL getVLMUL() const {
616-
assert(isValid() && !isUnknown() &&
618+
assert(isValid() && !isUnknown() && !hasSEWLMULRatioOnly() &&
617619
"Can't use VTYPE for uninitialized or unknown");
618620
return VLMul;
619621
}
@@ -727,8 +729,6 @@ class VSETVLIInfo {
727729
AltFmt);
728730
}
729731

730-
bool hasSEWLMULRatioOnly() const { return SEWLMULRatioOnly; }
731-
732732
bool hasSameVTYPE(const VSETVLIInfo &Other) const {
733733
assert(isValid() && Other.isValid() &&
734734
"Can't compare invalid VSETVLIInfos");
@@ -1317,8 +1317,8 @@ static VSETVLIInfo adjustIncoming(const VSETVLIInfo &PrevInfo,
13171317

13181318
if (!Demanded.LMUL && !Demanded.SEWLMULRatio && PrevInfo.isValid() &&
13191319
!PrevInfo.isUnknown()) {
1320-
if (auto NewVLMul = RISCVVType::getSameRatioLMUL(
1321-
PrevInfo.getSEW(), PrevInfo.getVLMUL(), Info.getSEW()))
1320+
if (auto NewVLMul = RISCVVType::getSameRatioLMUL(PrevInfo.getSEWLMULRatio(),
1321+
Info.getSEW()))
13221322
Info.setVLMul(*NewVLMul);
13231323
Demanded.LMUL = DemandedFields::LMULEqual;
13241324
}
@@ -1371,25 +1371,25 @@ void RISCVInsertVSETVLI::transferBefore(VSETVLIInfo &Info,
13711371
if (Demanded.VLAny || (Demanded.VLZeroness && !EquallyZero))
13721372
Info.setAVL(IncomingInfo);
13731373

1374-
Info.setVTYPE(
1375-
((Demanded.LMUL || Demanded.SEWLMULRatio) ? IncomingInfo : Info)
1376-
.getVLMUL(),
1377-
((Demanded.SEW || Demanded.SEWLMULRatio) ? IncomingInfo : Info).getSEW(),
1378-
// Prefer tail/mask agnostic since it can be relaxed to undisturbed later
1379-
// if needed.
1380-
(Demanded.TailPolicy ? IncomingInfo : Info).getTailAgnostic() ||
1381-
IncomingInfo.getTailAgnostic(),
1382-
(Demanded.MaskPolicy ? IncomingInfo : Info).getMaskAgnostic() ||
1383-
IncomingInfo.getMaskAgnostic(),
1384-
(Demanded.AltFmt ? IncomingInfo : Info).getAltFmt(),
1385-
Demanded.TWiden ? IncomingInfo.getTWiden() : 0);
1386-
1387-
// If we only knew the sew/lmul ratio previously, replace the VTYPE but keep
1388-
// the AVL.
1374+
// If we only knew the sew/lmul ratio previously, replace the VTYPE.
13891375
if (Info.hasSEWLMULRatioOnly()) {
13901376
VSETVLIInfo RatiolessInfo = IncomingInfo;
13911377
RatiolessInfo.setAVL(Info);
13921378
Info = RatiolessInfo;
1379+
} else {
1380+
Info.setVTYPE(
1381+
((Demanded.LMUL || Demanded.SEWLMULRatio) ? IncomingInfo : Info)
1382+
.getVLMUL(),
1383+
((Demanded.SEW || Demanded.SEWLMULRatio) ? IncomingInfo : Info)
1384+
.getSEW(),
1385+
// Prefer tail/mask agnostic since it can be relaxed to undisturbed
1386+
// later if needed.
1387+
(Demanded.TailPolicy ? IncomingInfo : Info).getTailAgnostic() ||
1388+
IncomingInfo.getTailAgnostic(),
1389+
(Demanded.MaskPolicy ? IncomingInfo : Info).getMaskAgnostic() ||
1390+
IncomingInfo.getMaskAgnostic(),
1391+
(Demanded.AltFmt ? IncomingInfo : Info).getAltFmt(),
1392+
Demanded.TWiden ? IncomingInfo.getTWiden() : 0);
13931393
}
13941394
}
13951395

llvm/lib/TargetParser/RISCVTargetParser.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,8 +244,7 @@ unsigned getSEWLMULRatio(unsigned SEW, VLMUL VLMul) {
244244
return (SEW * 8) / LMul;
245245
}
246246

247-
std::optional<VLMUL> getSameRatioLMUL(unsigned SEW, VLMUL VLMul, unsigned EEW) {
248-
unsigned Ratio = RISCVVType::getSEWLMULRatio(SEW, VLMul);
247+
std::optional<VLMUL> getSameRatioLMUL(unsigned Ratio, unsigned EEW) {
249248
unsigned EMULFixedPoint = (EEW * 8) / Ratio;
250249
bool Fractional = EMULFixedPoint < 8;
251250
unsigned EMUL = Fractional ? 8 / EMULFixedPoint : EMULFixedPoint / 8;

llvm/unittests/TargetParser/RISCVTargetParserTest.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,25 @@ namespace {
1515
TEST(RISCVVType, CheckSameRatioLMUL) {
1616
// Smaller LMUL.
1717
EXPECT_EQ(RISCVVType::LMUL_1,
18-
RISCVVType::getSameRatioLMUL(16, RISCVVType::LMUL_2, 8));
18+
RISCVVType::getSameRatioLMUL(
19+
RISCVVType::getSEWLMULRatio(16, RISCVVType::LMUL_2), 8));
1920
EXPECT_EQ(RISCVVType::LMUL_F2,
20-
RISCVVType::getSameRatioLMUL(16, RISCVVType::LMUL_1, 8));
21+
RISCVVType::getSameRatioLMUL(
22+
RISCVVType::getSEWLMULRatio(16, RISCVVType::LMUL_1), 8));
2123
// Smaller fractional LMUL.
2224
EXPECT_EQ(RISCVVType::LMUL_F8,
23-
RISCVVType::getSameRatioLMUL(16, RISCVVType::LMUL_F4, 8));
25+
RISCVVType::getSameRatioLMUL(
26+
RISCVVType::getSEWLMULRatio(16, RISCVVType::LMUL_F4), 8));
2427
// Bigger LMUL.
2528
EXPECT_EQ(RISCVVType::LMUL_2,
26-
RISCVVType::getSameRatioLMUL(8, RISCVVType::LMUL_1, 16));
29+
RISCVVType::getSameRatioLMUL(
30+
RISCVVType::getSEWLMULRatio(8, RISCVVType::LMUL_1), 16));
2731
EXPECT_EQ(RISCVVType::LMUL_1,
28-
RISCVVType::getSameRatioLMUL(8, RISCVVType::LMUL_F2, 16));
32+
RISCVVType::getSameRatioLMUL(
33+
RISCVVType::getSEWLMULRatio(8, RISCVVType::LMUL_F2), 16));
2934
// Bigger fractional LMUL.
3035
EXPECT_EQ(RISCVVType::LMUL_F2,
31-
RISCVVType::getSameRatioLMUL(8, RISCVVType::LMUL_F4, 16));
36+
RISCVVType::getSameRatioLMUL(
37+
RISCVVType::getSEWLMULRatio(8, RISCVVType::LMUL_F4), 16));
3238
}
3339
} // namespace

0 commit comments

Comments
 (0)