[llvm] [VPlan] Add initial loop-invariant code motion transform. (PR #107894)

Ramkumar Ramachandra via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 13 11:35:17 PDT 2024


================
@@ -1587,3 +1588,24 @@ void VPlanTransforms::createInterleaveGroups(
       }
   }
 }
+
+void VPlanTransforms::licm(VPlan &Plan) {
+  VPRegionBlock *LoopRegion = Plan.getVectorLoopRegion();
+  VPBasicBlock *Preheader =
+      cast<VPBasicBlock>(LoopRegion->getSinglePredecessor());
+  // Hoist any loop invariant recipes from the vector loop region to the
+  // preheader.
+  for (VPBasicBlock *VPBB : VPBlockUtils::blocksOnly<VPBasicBlock>(
+           vp_depth_first_shallow(LoopRegion->getEntry()))) {
+    for (VPRecipeBase &R : make_early_inc_range(*VPBB)) {
+      // TODO: Relax checks in the future, e.g. we could also hoist reads, if
+      // their memory location is not modified in the vector loop.
+      if (R.mayHaveSideEffects() || R.mayReadFromMemory() || R.isPhi() ||
+          any_of(R.operands(), [](VPValue *Op) {
----------------
artagnon wrote:

Also, I was thinking: the right condition for LICM is "def dominates all its uses"; do you think this is feasible to check with the current infrastructure?

https://github.com/llvm/llvm-project/pull/107894


More information about the llvm-commits mailing list