[RISCV][InsertVSETVL] Incorporate demanded fields into compatibility interface [nfc]
authorPhilip Reames <preames@rivosinc.com>
Thu, 15 Dec 2022 19:09:49 +0000 (11:09 -0800)
committerPhilip Reames <listmail@philipreames.com>
Thu, 15 Dec 2022 19:11:09 +0000 (11:11 -0800)
This reworks the API to explicitly pass in the demanded fields instead of requering them internally.  At the moment, this is NFC, but it will stop being so in future changes which adjust the demanded bits in the caller.

llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp

index 62a92ab26bd7c9d05d26c3480d452fd7e7c33a65..dddcd5dcf7fa8af654d662b2573ab4a9d8afc2af 100644 (file)
@@ -399,16 +399,15 @@ public:
            MaskAgnostic == Other.MaskAgnostic;
   }
 
-  bool hasCompatibleVTYPE(const MachineInstr &MI,
+  bool hasCompatibleVTYPE(const DemandedFields &Used,
                           const VSETVLIInfo &Require) const {
-    const DemandedFields Used = getDemanded(MI);
     return areCompatibleVTYPEs(encodeVTYPE(), Require.encodeVTYPE(), Used);
   }
 
   // Determine whether the vector instructions requirements represented by
   // Require are compatible with the previous vsetvli instruction represented
   // by this.  MI is the instruction whose requirements we're considering.
-  bool isCompatible(const MachineInstr &MI, const VSETVLIInfo &Require) const {
+  bool isCompatible(const DemandedFields &Used, const VSETVLIInfo &Require) const {
     assert(isValid() && Require.isValid() &&
            "Can't compare invalid VSETVLIInfos");
     assert(!Require.SEWLMULRatioOnly &&
@@ -427,7 +426,10 @@ public:
       if (SEW == Require.SEW)
         return true;
 
-    return hasSameAVL(Require) && hasCompatibleVTYPE(MI, Require);
+    // TODO: Check Used.VL here
+    if (!hasSameAVL(Require))
+      return false;
+    return areCompatibleVTYPEs(encodeVTYPE(), Require.encodeVTYPE(), Used);
   }
 
   bool operator==(const VSETVLIInfo &Other) const {
@@ -774,7 +776,8 @@ bool RISCVInsertVSETVLI::needVSETVLI(const MachineInstr &MI,
   if (!CurInfo.isValid() || CurInfo.isUnknown() || CurInfo.hasSEWLMULRatioOnly())
     return true;
 
-  if (CurInfo.isCompatible(MI, Require))
+  const DemandedFields Used = getDemanded(MI);
+  if (CurInfo.isCompatible(Used, Require))
     return false;
 
   // For vmv.s.x and vfmv.s.f, there is only two behaviors, VL = 0 and VL > 0.
@@ -795,7 +798,7 @@ bool RISCVInsertVSETVLI::needVSETVLI(const MachineInstr &MI,
   // and the last VL/VTYPE we observed is the same, we don't need a
   // VSETVLI here.
   if (Require.hasAVLReg() && Require.getAVLReg().isVirtual() &&
-      CurInfo.hasCompatibleVTYPE(MI, Require)) {
+      CurInfo.hasCompatibleVTYPE(Used, Require)) {
     if (MachineInstr *DefMI = MRI->getVRegDef(Require.getAVLReg())) {
       if (isVectorConfigInstr(*DefMI)) {
         VSETVLIInfo DefInfo = getInfoForVSETVLI(*DefMI);