[llvm] [RISCV] Convert AVLs with vlenb to VLMAX where possible (PR #97800)
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 10 20:40:35 PDT 2024
================
@@ -58,11 +70,62 @@ class RISCVFoldMasks : public MachineFunctionPass {
} // namespace
-char RISCVFoldMasks::ID = 0;
+char RISCVVectorPeephole::ID = 0;
+
+INITIALIZE_PASS(RISCVVectorPeephole, DEBUG_TYPE, "RISC-V Fold Masks", false,
+ false)
+
+// If an AVL is a VLENB that's possibly scaled to be equal to VLMAX, convert it
+// to the VLMAX sentinel value.
+bool RISCVVectorPeephole::convertToVLMAX(MachineInstr &MI) const {
+ if (!RISCVII::hasVLOp(MI.getDesc().TSFlags) ||
+ !RISCVII::hasSEWOp(MI.getDesc().TSFlags))
+ return false;
+ MachineOperand &VL = MI.getOperand(RISCVII::getVLOpNum(MI.getDesc()));
+ if (!VL.isReg())
+ return false;
+ MachineInstr *Def = MRI->getVRegDef(VL.getReg());
+ if (!Def)
+ return false;
+
+ // Fixed-point value, denominator=8
+ unsigned ScaleFixed = 8;
+ // Check if the VLENB was potentially scaled with slli/srli
+ if (Def->getOpcode() == RISCV::SLLI) {
+ ScaleFixed <<= Def->getOperand(2).getImm();
----------------
topperc wrote:
Do we need to check that the shift amount isn't out of bounds?
https://github.com/llvm/llvm-project/pull/97800
More information about the llvm-commits
mailing list