[PATCH] D143422: [LV] Update logic for calculating register usage due to invariants

Sander de Smalen via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 21 01:58:02 PST 2023


sdesmalen added inline comments.


================
Comment at: llvm/lib/Transforms/Vectorize/LoopVectorize.cpp:6094
+
+      for (auto *User : dyn_cast<Instruction>(Inst)->users()) {
+        Instruction *I = dyn_cast<Instruction>(User);
----------------
It seems that Inst can only ever be an `Instruction`, so this can be a `cast`. It would be even better to make LoopInvariants be a SmallVector of `Instruction` rather than `Value` (as a NFC precursory patch) , given that the loop that populates it skips non-Instruction values. 


================
Comment at: llvm/lib/Transforms/Vectorize/LoopVectorize.cpp:6096
+        Instruction *I = dyn_cast<Instruction>(User);
+        if (TheLoop != LI->getLoopFor(I->getParent()))
+          continue;
----------------
If `User` is not a `Instruction`, the `dyn_cast` will result in a `nullptr` and the call to `getParent()` will fail.


================
Comment at: llvm/lib/Transforms/Vectorize/LoopVectorize.cpp:6122
+      }
     }
 
----------------
I think you can write the algorithm above a bit shorter using a lambda:

  bool IsScalar = all_of(cast<Instruction>(Inst)->users(), [&](User *U) {
    auto *I = dyn_cast<Instruction>(U);
    return !I || TheLoop != LI->getLoopFor(I->getParent()) ||
           isScalarAfterVectorization(I, VFs[i]);
  });      
  
  ElementCount VF = IsScalar ? ElementCount::getFixed(1) : VFs[i];
  unsigned  ClassID = TTI.getRegisterClassForType(VF.isVector(), Inst->getType());
  Invariant[ClassID] += GetRegusage(Inst->getType(), VF);;



CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D143422/new/

https://reviews.llvm.org/D143422



More information about the llvm-commits mailing list