-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[VPlan] Add initial loop-invariant code motion transform. #107894
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
7e9a5f8
3caeea3
f93524c
578ec3e
a3ac937
62a24af
eb9dc17
b996541
9807dfe
7817971
fa1d94f
46636d8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1128,6 +1128,7 @@ void VPlanTransforms::optimize(VPlan &Plan, ScalarEvolution &SE) { | |
removeRedundantInductionCasts(Plan); | ||
|
||
simplifyRecipes(Plan, SE.getContext()); | ||
licm(Plan); | ||
legalizeAndOptimizeInductions(Plan, SE); | ||
removeDeadRecipes(Plan); | ||
|
||
|
@@ -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()))) { | ||
artagnon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Technically an op can still be hoisted if it reads from memory with no side effects, as long as the pointer is constant throughout the loop, which the What cases are you thinking here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the memory is not modified in the loop we could also hoist out reads, but I think at the moment we don't yet have to utilities available to check that on the VPlan level. Added a TODO to further relax the checks and improve the analysis.
artagnon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return !Op->isDefinedOutsideVectorRegions(); | ||
})) | ||
continue; | ||
R.moveBefore(*Preheader, Preheader->end()); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(strictly speaking, qualifies as
GrandParent
;-))There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps we should introduce
getParentRegion
orgetRegion
, similar toInstruction::getFunction
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe
getEnclosingRegion()
, to complement and servegetEnclosingLoopRegion()
?