Skip to content

Commit 7129205

Browse files
[LoopVectorize] Move checking for OptForSize into the cost model (NFC) (#130752)
Move OptForSizeBasedOnProfile into the cost model and rename it to OptForSize, as shouldOptimizeForSize checks both the function attribute and profile. This being done in preparation for OptForSize being used in the cost model.
1 parent fb397ab commit 7129205

File tree

1 file changed

+16
-17
lines changed

1 file changed

+16
-17
lines changed

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -494,12 +494,7 @@ class InnerLoopVectorizer {
494494
MinProfitableTripCount(MinProfitableTripCount), UF(UnrollFactor),
495495
Builder(PSE.getSE()->getContext()), Legal(LVL), Cost(CM), BFI(BFI),
496496
PSI(PSI), RTChecks(RTChecks), Plan(Plan),
497-
VectorPHVPB(Plan.getEntry()->getSingleSuccessor()) {
498-
// Query this against the original loop and save it here because the profile
499-
// of the original loop header may change as the transformation happens.
500-
OptForSizeBasedOnProfile = llvm::shouldOptimizeForSize(
501-
OrigLoop->getHeader(), PSI, BFI, PGSOQueryType::IRPass);
502-
}
497+
VectorPHVPB(Plan.getEntry()->getSingleSuccessor()) {}
503498

504499
virtual ~InnerLoopVectorizer() = default;
505500

@@ -672,10 +667,6 @@ class InnerLoopVectorizer {
672667
BlockFrequencyInfo *BFI;
673668
ProfileSummaryInfo *PSI;
674669

675-
// Whether this loop should be optimized for size based on profile guided size
676-
// optimizatios.
677-
bool OptForSizeBasedOnProfile;
678-
679670
/// Structure to hold information about generated runtime checks, responsible
680671
/// for cleaning the checks, if vectorization turns out unprofitable.
681672
GeneratedRTChecks &RTChecks;
@@ -987,13 +978,18 @@ class LoopVectorizationCostModel {
987978
AssumptionCache *AC,
988979
OptimizationRemarkEmitter *ORE, const Function *F,
989980
const LoopVectorizeHints *Hints,
990-
InterleavedAccessInfo &IAI)
981+
InterleavedAccessInfo &IAI,
982+
ProfileSummaryInfo *PSI, BlockFrequencyInfo *BFI)
991983
: ScalarEpilogueStatus(SEL), TheLoop(L), PSE(PSE), LI(LI), Legal(Legal),
992984
TTI(TTI), TLI(TLI), DB(DB), AC(AC), ORE(ORE), TheFunction(F),
993985
Hints(Hints), InterleaveInfo(IAI) {
994986
if (TTI.supportsScalableVectors() || ForceTargetSupportsScalableVectors)
995987
initializeVScaleForTuning();
996988
CostKind = F->hasMinSize() ? TTI::TCK_CodeSize : TTI::TCK_RecipThroughput;
989+
// Query this against the original loop and save it here because the profile
990+
// of the original loop header may change as the transformation happens.
991+
OptForSize = llvm::shouldOptimizeForSize(L->getHeader(), PSI, BFI,
992+
PGSOQueryType::IRPass);
997993
}
998994

999995
/// \return An upper bound for the vectorization factors (both fixed and
@@ -1830,6 +1826,10 @@ class LoopVectorizationCostModel {
18301826

18311827
/// The kind of cost that we are calculating
18321828
TTI::TargetCostKind CostKind;
1829+
1830+
/// Whether this loop should be optimized for size based on function attribute
1831+
/// or profile information.
1832+
bool OptForSize;
18331833
};
18341834
} // end namespace llvm
18351835

@@ -2602,9 +2602,8 @@ BasicBlock *InnerLoopVectorizer::emitSCEVChecks(BasicBlock *Bypass) {
26022602
if (!SCEVCheckBlock)
26032603
return nullptr;
26042604

2605-
assert(!(SCEVCheckBlock->getParent()->hasOptSize() ||
2606-
(OptForSizeBasedOnProfile &&
2607-
Cost->Hints->getForce() != LoopVectorizeHints::FK_Enabled)) &&
2605+
assert((!Cost->OptForSize ||
2606+
Cost->Hints->getForce() == LoopVectorizeHints::FK_Enabled) &&
26082607
"Cannot SCEV check stride or overflow when optimizing for size");
26092608
assert(!LoopBypassBlocks.empty() &&
26102609
"Should already be a bypass block due to iteration count check");
@@ -2629,7 +2628,7 @@ BasicBlock *InnerLoopVectorizer::emitMemRuntimeChecks(BasicBlock *Bypass) {
26292628
assert((!EnableVPlanNativePath || OrigLoop->begin() == OrigLoop->end()) &&
26302629
"Runtime checks are not supported for outer loops yet");
26312630

2632-
if (MemCheckBlock->getParent()->hasOptSize() || OptForSizeBasedOnProfile) {
2631+
if (Cost->OptForSize) {
26332632
assert(Cost->Hints->getForce() == LoopVectorizeHints::FK_Enabled &&
26342633
"Cannot emit memory checks when optimizing for size, unless forced "
26352634
"to vectorize.");
@@ -10083,7 +10082,7 @@ static bool processLoopInVPlanNativePath(
1008310082
getScalarEpilogueLowering(F, L, Hints, PSI, BFI, TTI, TLI, *LVL, &IAI);
1008410083

1008510084
LoopVectorizationCostModel CM(SEL, L, PSE, LI, LVL, *TTI, TLI, DB, AC, ORE, F,
10086-
&Hints, IAI);
10085+
&Hints, IAI, PSI, BFI);
1008710086
// Use the planner for outer loop vectorization.
1008810087
// TODO: CM is not used at this point inside the planner. Turn CM into an
1008910088
// optional argument if we don't need it in the future.
@@ -10659,7 +10658,7 @@ bool LoopVectorizePass::processLoop(Loop *L) {
1065910658

1066010659
// Use the cost model.
1066110660
LoopVectorizationCostModel CM(SEL, L, PSE, LI, &LVL, *TTI, TLI, DB, AC, ORE,
10662-
F, &Hints, IAI);
10661+
F, &Hints, IAI, PSI, BFI);
1066310662
// Use the planner for vectorization.
1066410663
LoopVectorizationPlanner LVP(L, LI, DT, TLI, *TTI, &LVL, CM, IAI, PSE, Hints,
1066510664
ORE);

0 commit comments

Comments
 (0)