[llvm] fbd1864 - [RISCV] Simplify EEW/EMUL check in VLOptimizer. NFC (#152100)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 5 01:53:44 PDT 2025
Author: Luke Lau
Date: 2025-08-05T16:53:41+08:00
New Revision: fbd18642a9eefc7bb3b7d40eaf8d16ef9d523064
URL: https://github.com/llvm/llvm-project/commit/fbd18642a9eefc7bb3b7d40eaf8d16ef9d523064
DIFF: https://github.com/llvm/llvm-project/commit/fbd18642a9eefc7bb3b7d40eaf8d16ef9d523064.diff
LOG: [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.
Added:
Modified:
llvm/lib/Target/RISCV/RISCVVLOptimizer.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Target/RISCV/RISCVVLOptimizer.cpp b/llvm/lib/Target/RISCV/RISCVVLOptimizer.cpp
index c9464515d2e56..37a71e8ec7689 100644
--- a/llvm/lib/Target/RISCV/RISCVVLOptimizer.cpp
+++ b/llvm/lib/Target/RISCV/RISCVVLOptimizer.cpp
@@ -69,6 +69,7 @@ struct OperandInfo {
// Represent as 1,2,4,8, ... and fractional indicator. This is because
// EMUL can take on values that don't map to RISCVVType::VLMUL values exactly.
// For example, a mask operand can have an EMUL less than MF8.
+ // If nullopt, then EMUL isn't used (i.e. only a single scalar is read).
std::optional<std::pair<unsigned, bool>> EMUL;
unsigned Log2EEW;
@@ -83,12 +84,14 @@ struct OperandInfo {
OperandInfo() = delete;
- static bool EMULAndEEWAreEqual(const OperandInfo &A, const OperandInfo &B) {
- return A.Log2EEW == B.Log2EEW && A.EMUL == B.EMUL;
- }
-
- static bool EEWAreEqual(const OperandInfo &A, const OperandInfo &B) {
- return A.Log2EEW == B.Log2EEW;
+ /// Return true if the EMUL and EEW produced by \p Def is compatible with the
+ /// EMUL and EEW used by \p User.
+ static bool areCompatible(const OperandInfo &Def, const OperandInfo &User) {
+ if (Def.Log2EEW != User.Log2EEW)
+ return false;
+ if (User.EMUL && Def.EMUL != User.EMUL)
+ return false;
+ return true;
}
void print(raw_ostream &OS) const {
@@ -98,7 +101,7 @@ struct OperandInfo {
OS << "f";
OS << EMUL->first;
} else
- OS << "EMUL: unknown\n";
+ OS << "EMUL: none\n";
OS << ", EEW: " << (1 << Log2EEW);
}
};
@@ -1399,13 +1402,7 @@ RISCVVLOptimizer::checkUsers(const MachineInstr &MI) const {
return std::nullopt;
}
- // If the operand is used as a scalar operand, then the EEW must be
- // compatible. Otherwise, the EMUL *and* EEW must be compatible.
- bool IsVectorOpUsedAsScalarOp = isVectorOpUsedAsScalarOp(UserOp);
- if ((IsVectorOpUsedAsScalarOp &&
- !OperandInfo::EEWAreEqual(*ConsumerInfo, *ProducerInfo)) ||
- (!IsVectorOpUsedAsScalarOp &&
- !OperandInfo::EMULAndEEWAreEqual(*ConsumerInfo, *ProducerInfo))) {
+ if (!OperandInfo::areCompatible(*ProducerInfo, *ConsumerInfo)) {
LLVM_DEBUG(
dbgs()
<< " Abort due to incompatible information for EMUL or EEW.\n");
More information about the llvm-commits
mailing list