Skip to content

Commit fbd1864

Browse files
authored
[RISCV] Simplify EEW/EMUL check in VLOptimizer. NFC (#152100)
Currently when checking to see if two OperandInfos are compatible, we check to see if the user operand only uses the first scalar and then do two different checks depending on that. However whether the user only uses the first scalar or not is already encoded in OperandInfo, when EMUL is nullopt. This removes the redundant check and keeps the logic in the OperandInfo class to make the call site easier to reason about.
1 parent f72b3e1 commit fbd1864

File tree

1 file changed

+11
-14
lines changed

1 file changed

+11
-14
lines changed

llvm/lib/Target/RISCV/RISCVVLOptimizer.cpp

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ struct OperandInfo {
6969
// Represent as 1,2,4,8, ... and fractional indicator. This is because
7070
// EMUL can take on values that don't map to RISCVVType::VLMUL values exactly.
7171
// For example, a mask operand can have an EMUL less than MF8.
72+
// If nullopt, then EMUL isn't used (i.e. only a single scalar is read).
7273
std::optional<std::pair<unsigned, bool>> EMUL;
7374

7475
unsigned Log2EEW;
@@ -83,12 +84,14 @@ struct OperandInfo {
8384

8485
OperandInfo() = delete;
8586

86-
static bool EMULAndEEWAreEqual(const OperandInfo &A, const OperandInfo &B) {
87-
return A.Log2EEW == B.Log2EEW && A.EMUL == B.EMUL;
88-
}
89-
90-
static bool EEWAreEqual(const OperandInfo &A, const OperandInfo &B) {
91-
return A.Log2EEW == B.Log2EEW;
87+
/// Return true if the EMUL and EEW produced by \p Def is compatible with the
88+
/// EMUL and EEW used by \p User.
89+
static bool areCompatible(const OperandInfo &Def, const OperandInfo &User) {
90+
if (Def.Log2EEW != User.Log2EEW)
91+
return false;
92+
if (User.EMUL && Def.EMUL != User.EMUL)
93+
return false;
94+
return true;
9295
}
9396

9497
void print(raw_ostream &OS) const {
@@ -98,7 +101,7 @@ struct OperandInfo {
98101
OS << "f";
99102
OS << EMUL->first;
100103
} else
101-
OS << "EMUL: unknown\n";
104+
OS << "EMUL: none\n";
102105
OS << ", EEW: " << (1 << Log2EEW);
103106
}
104107
};
@@ -1399,13 +1402,7 @@ RISCVVLOptimizer::checkUsers(const MachineInstr &MI) const {
13991402
return std::nullopt;
14001403
}
14011404

1402-
// If the operand is used as a scalar operand, then the EEW must be
1403-
// compatible. Otherwise, the EMUL *and* EEW must be compatible.
1404-
bool IsVectorOpUsedAsScalarOp = isVectorOpUsedAsScalarOp(UserOp);
1405-
if ((IsVectorOpUsedAsScalarOp &&
1406-
!OperandInfo::EEWAreEqual(*ConsumerInfo, *ProducerInfo)) ||
1407-
(!IsVectorOpUsedAsScalarOp &&
1408-
!OperandInfo::EMULAndEEWAreEqual(*ConsumerInfo, *ProducerInfo))) {
1405+
if (!OperandInfo::areCompatible(*ProducerInfo, *ConsumerInfo)) {
14091406
LLVM_DEBUG(
14101407
dbgs()
14111408
<< " Abort due to incompatible information for EMUL or EEW.\n");

0 commit comments

Comments
 (0)