@@ -927,6 +927,7 @@ class RISCVInsertVSETVLI : public MachineFunctionPass {
927
927
928
928
VSETVLIInfo getInfoForVSETVLI (const MachineInstr &MI) const ;
929
929
VSETVLIInfo computeInfoForInstr (const MachineInstr &MI) const ;
930
+ void forwardVSETVLIAVL (VSETVLIInfo &Info) const ;
930
931
};
931
932
932
933
} // end anonymous namespace
@@ -937,6 +938,26 @@ char &llvm::RISCVInsertVSETVLIID = RISCVInsertVSETVLI::ID;
937
938
INITIALIZE_PASS (RISCVInsertVSETVLI, DEBUG_TYPE, RISCV_INSERT_VSETVLI_NAME,
938
939
false , false )
939
940
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
+
940
961
// Return a VSETVLIInfo representing the changes made by this VSETVLI or
941
962
// VSETIVLI instruction.
942
963
VSETVLIInfo
@@ -962,16 +983,7 @@ RISCVInsertVSETVLI::getInfoForVSETVLI(const MachineInstr &MI) const {
962
983
}
963
984
NewInfo.setVTYPE (MI.getOperand (2 ).getImm ());
964
985
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);
975
987
976
988
return NewInfo;
977
989
}
@@ -1060,16 +1072,7 @@ RISCVInsertVSETVLI::computeInfoForInstr(const MachineInstr &MI) const {
1060
1072
#endif
1061
1073
InstrInfo.setVTYPE (VLMul, SEW, TailAgnostic, MaskAgnostic);
1062
1074
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);
1073
1076
1074
1077
return InstrInfo;
1075
1078
}
0 commit comments