Skip to content

Commit f76ea31

Browse files
committed
[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.
1 parent 4311b14 commit f76ea31

File tree

1 file changed

+23
-20
lines changed

1 file changed

+23
-20
lines changed

llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -927,6 +927,7 @@ class RISCVInsertVSETVLI : public MachineFunctionPass {
927927

928928
VSETVLIInfo getInfoForVSETVLI(const MachineInstr &MI) const;
929929
VSETVLIInfo computeInfoForInstr(const MachineInstr &MI) const;
930+
void forwardVSETVLIAVL(VSETVLIInfo &Info) const;
930931
};
931932

932933
} // end anonymous namespace
@@ -937,6 +938,26 @@ char &llvm::RISCVInsertVSETVLIID = RISCVInsertVSETVLI::ID;
937938
INITIALIZE_PASS(RISCVInsertVSETVLI, DEBUG_TYPE, RISCV_INSERT_VSETVLI_NAME,
938939
false, false)
939940

941+
// If the AVL is defined by a vsetvli's output vl with the same VLMAX, we can
942+
// replace the AVL operand with the AVL of the defining vsetvli. E.g.
943+
//
944+
// %vl = PseudoVSETVLI %avl:gpr, SEW=32, LMUL=M1
945+
// $x0 = PseudoVSETVLI %vl:gpr, SEW=32, LMUL=M1
946+
// ->
947+
// %vl = PseudoVSETVLI %avl:gpr, SEW=32, LMUL=M1
948+
// $x0 = PseudoVSETVLI %avl:gpr, SEW=32, LMUL=M1
949+
void RISCVInsertVSETVLI::forwardVSETVLIAVL(VSETVLIInfo &Info) const {
950+
if (!Info.hasAVLReg())
951+
return;
952+
const MachineInstr *DefMI = Info.getAVLDefMI(LIS);
953+
if (!DefMI || !isVectorConfigInstr(*DefMI))
954+
return;
955+
VSETVLIInfo DefInstrInfo = getInfoForVSETVLI(*DefMI);
956+
if (!DefInstrInfo.hasSameVLMAX(Info))
957+
return;
958+
Info.setAVL(DefInstrInfo);
959+
}
960+
940961
// Return a VSETVLIInfo representing the changes made by this VSETVLI or
941962
// VSETIVLI instruction.
942963
VSETVLIInfo
@@ -962,16 +983,7 @@ RISCVInsertVSETVLI::getInfoForVSETVLI(const MachineInstr &MI) const {
962983
}
963984
NewInfo.setVTYPE(MI.getOperand(2).getImm());
964985

965-
// If AVL is defined by a vsetvli with the same VLMAX, we can replace the
966-
// AVL operand with the AVL of the defining vsetvli.
967-
if (NewInfo.hasAVLReg()) {
968-
if (const MachineInstr *DefMI = NewInfo.getAVLDefMI(LIS);
969-
DefMI && isVectorConfigInstr(*DefMI)) {
970-
VSETVLIInfo DefInstrInfo = getInfoForVSETVLI(*DefMI);
971-
if (DefInstrInfo.hasSameVLMAX(NewInfo))
972-
NewInfo.setAVL(DefInstrInfo);
973-
}
974-
}
986+
forwardVSETVLIAVL(NewInfo);
975987

976988
return NewInfo;
977989
}
@@ -1060,16 +1072,7 @@ RISCVInsertVSETVLI::computeInfoForInstr(const MachineInstr &MI) const {
10601072
#endif
10611073
InstrInfo.setVTYPE(VLMul, SEW, TailAgnostic, MaskAgnostic);
10621074

1063-
// If AVL is defined by a vsetvli with the same VLMAX, we can replace the
1064-
// AVL operand with the AVL of the defining vsetvli.
1065-
if (InstrInfo.hasAVLReg()) {
1066-
if (const MachineInstr *DefMI = InstrInfo.getAVLDefMI(LIS);
1067-
DefMI && isVectorConfigInstr(*DefMI)) {
1068-
VSETVLIInfo DefInstrInfo = getInfoForVSETVLI(*DefMI);
1069-
if (DefInstrInfo.hasSameVLMAX(InstrInfo))
1070-
InstrInfo.setAVL(DefInstrInfo);
1071-
}
1072-
}
1075+
forwardVSETVLIAVL(InstrInfo);
10731076

10741077
return InstrInfo;
10751078
}

0 commit comments

Comments
 (0)