[llvm] f76ea31 - [RISCV] Deduplicate AVL forwarding in RISCVInsertVSETVLI. NFC
Luke Lau via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 1 01:25:40 PDT 2024
Author: Luke Lau
Date: 2024-07-01T16:25:05+08:00
New Revision: f76ea319960161525bced4e3091ba4383714af7a
URL: https://github.com/llvm/llvm-project/commit/f76ea319960161525bced4e3091ba4383714af7a
DIFF: https://github.com/llvm/llvm-project/commit/f76ea319960161525bced4e3091ba4383714af7a.diff
LOG: [RISCV] Deduplicate AVL forwarding in RISCVInsertVSETVLI. NFC
We do the AVL forwarding trick in both getInfoForVSETVLI and
computeInfoForInstr, but there's a bug with this that I plan on fixing
in an upcoming patch. This factors it out to so we only need to fix it
in one place.
Added:
Modified:
llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp b/llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp
index 7abd7dc4957a0..bf693344b070a 100644
--- a/llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp
+++ b/llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp
@@ -927,6 +927,7 @@ class RISCVInsertVSETVLI : public MachineFunctionPass {
VSETVLIInfo getInfoForVSETVLI(const MachineInstr &MI) const;
VSETVLIInfo computeInfoForInstr(const MachineInstr &MI) const;
+ void forwardVSETVLIAVL(VSETVLIInfo &Info) const;
};
} // end anonymous namespace
@@ -937,6 +938,26 @@ char &llvm::RISCVInsertVSETVLIID = RISCVInsertVSETVLI::ID;
INITIALIZE_PASS(RISCVInsertVSETVLI, DEBUG_TYPE, RISCV_INSERT_VSETVLI_NAME,
false, false)
+// If the AVL is defined by a vsetvli's output vl with the same VLMAX, we can
+// replace the AVL operand with the AVL of the defining vsetvli. E.g.
+//
+// %vl = PseudoVSETVLI %avl:gpr, SEW=32, LMUL=M1
+// $x0 = PseudoVSETVLI %vl:gpr, SEW=32, LMUL=M1
+// ->
+// %vl = PseudoVSETVLI %avl:gpr, SEW=32, LMUL=M1
+// $x0 = PseudoVSETVLI %avl:gpr, SEW=32, LMUL=M1
+void RISCVInsertVSETVLI::forwardVSETVLIAVL(VSETVLIInfo &Info) const {
+ if (!Info.hasAVLReg())
+ return;
+ const MachineInstr *DefMI = Info.getAVLDefMI(LIS);
+ if (!DefMI || !isVectorConfigInstr(*DefMI))
+ return;
+ VSETVLIInfo DefInstrInfo = getInfoForVSETVLI(*DefMI);
+ if (!DefInstrInfo.hasSameVLMAX(Info))
+ return;
+ Info.setAVL(DefInstrInfo);
+}
+
// Return a VSETVLIInfo representing the changes made by this VSETVLI or
// VSETIVLI instruction.
VSETVLIInfo
@@ -962,16 +983,7 @@ RISCVInsertVSETVLI::getInfoForVSETVLI(const MachineInstr &MI) const {
}
NewInfo.setVTYPE(MI.getOperand(2).getImm());
- // If AVL is defined by a vsetvli with the same VLMAX, we can replace the
- // AVL operand with the AVL of the defining vsetvli.
- if (NewInfo.hasAVLReg()) {
- if (const MachineInstr *DefMI = NewInfo.getAVLDefMI(LIS);
- DefMI && isVectorConfigInstr(*DefMI)) {
- VSETVLIInfo DefInstrInfo = getInfoForVSETVLI(*DefMI);
- if (DefInstrInfo.hasSameVLMAX(NewInfo))
- NewInfo.setAVL(DefInstrInfo);
- }
- }
+ forwardVSETVLIAVL(NewInfo);
return NewInfo;
}
@@ -1060,16 +1072,7 @@ RISCVInsertVSETVLI::computeInfoForInstr(const MachineInstr &MI) const {
#endif
InstrInfo.setVTYPE(VLMul, SEW, TailAgnostic, MaskAgnostic);
- // If AVL is defined by a vsetvli with the same VLMAX, we can replace the
- // AVL operand with the AVL of the defining vsetvli.
- if (InstrInfo.hasAVLReg()) {
- if (const MachineInstr *DefMI = InstrInfo.getAVLDefMI(LIS);
- DefMI && isVectorConfigInstr(*DefMI)) {
- VSETVLIInfo DefInstrInfo = getInfoForVSETVLI(*DefMI);
- if (DefInstrInfo.hasSameVLMAX(InstrInfo))
- InstrInfo.setAVL(DefInstrInfo);
- }
- }
+ forwardVSETVLIAVL(InstrInfo);
return InstrInfo;
}
More information about the llvm-commits
mailing list