[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:10:42 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:
I'd recommend changing this to if `if (all_of(R.operands(), ... Op->isDefinedOutsideVectorRegions())) R.moveBefore(...)`, and having the continue branch for `R.mayHaveSideEffects()` etc.
https://github.com/llvm/llvm-project/pull/107894
More information about the llvm-commits
mailing list