-
Notifications
You must be signed in to change notification settings - Fork 15.5k
[VPlan] Simplify live-ins early using SCEV. #155304
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 all commits
97b6a0c
05b8c93
54e2924
e79f827
99e62cb
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 |
|---|---|---|
|
|
@@ -20,6 +20,7 @@ | |
| #include "llvm/Analysis/LoopInfo.h" | ||
| #include "llvm/Analysis/LoopIterator.h" | ||
| #include "llvm/Analysis/ScalarEvolution.h" | ||
| #include "llvm/Analysis/ScalarEvolutionExpressions.h" | ||
| #include "llvm/IR/InstrTypes.h" | ||
| #include "llvm/IR/MDBuilder.h" | ||
| #include "llvm/Transforms/Utils/LoopUtils.h" | ||
|
|
@@ -566,13 +567,30 @@ static void addInitialSkeleton(VPlan &Plan, Type *InductionTy, DebugLoc IVDL, | |
| } | ||
| } | ||
|
|
||
| /// Check \p Plan's live-in and replace them with constants, if they can be | ||
| /// simplified via SCEV. | ||
| static void simplifyLiveInsWithSCEV(VPlan &Plan, ScalarEvolution &SE) { | ||
| auto GetSimplifiedLiveInViaSCEV = [&](VPValue *VPV) -> VPValue * { | ||
| const SCEV *Expr = vputils::getSCEVExprForVPValue(VPV, SE); | ||
| if (auto *C = dyn_cast<SCEVConstant>(Expr)) | ||
| return Plan.getOrAddLiveIn(C->getValue()); | ||
| return nullptr; | ||
| }; | ||
|
|
||
| for (VPValue *LiveIn : Plan.getLiveIns()) { | ||
| if (VPValue *SimplifiedLiveIn = GetSimplifiedLiveInViaSCEV(LiveIn)) | ||
| LiveIn->replaceAllUsesWith(SimplifiedLiveIn); | ||
| } | ||
| } | ||
|
|
||
| std::unique_ptr<VPlan> | ||
| VPlanTransforms::buildVPlan0(Loop *TheLoop, LoopInfo &LI, Type *InductionTy, | ||
| DebugLoc IVDL, PredicatedScalarEvolution &PSE, | ||
| LoopVersioning *LVer) { | ||
| PlainCFGBuilder Builder(TheLoop, &LI, LVer); | ||
| std::unique_ptr<VPlan> VPlan0 = Builder.buildPlainCFG(); | ||
| addInitialSkeleton(*VPlan0, InductionTy, IVDL, PSE, TheLoop); | ||
| simplifyLiveInsWithSCEV(*VPlan0, *PSE.getSE()); | ||
|
Collaborator
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. Better doing so here this way than as a vplan-to-vplan transform, because expected to apply only once, which can be at construction?
Contributor
Author
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. Yep, we shouldn't add simplify-able live-ins later on I think |
||
| return VPlan0; | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.