@@ -494,12 +494,7 @@ class InnerLoopVectorizer {
494
494
MinProfitableTripCount(MinProfitableTripCount), UF(UnrollFactor),
495
495
Builder(PSE.getSE()->getContext()), Legal(LVL), Cost(CM), BFI(BFI),
496
496
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()) {}
503
498
504
499
virtual ~InnerLoopVectorizer () = default ;
505
500
@@ -672,10 +667,6 @@ class InnerLoopVectorizer {
672
667
BlockFrequencyInfo *BFI;
673
668
ProfileSummaryInfo *PSI;
674
669
675
- // Whether this loop should be optimized for size based on profile guided size
676
- // optimizatios.
677
- bool OptForSizeBasedOnProfile;
678
-
679
670
// / Structure to hold information about generated runtime checks, responsible
680
671
// / for cleaning the checks, if vectorization turns out unprofitable.
681
672
GeneratedRTChecks &RTChecks;
@@ -987,13 +978,18 @@ class LoopVectorizationCostModel {
987
978
AssumptionCache *AC,
988
979
OptimizationRemarkEmitter *ORE, const Function *F,
989
980
const LoopVectorizeHints *Hints,
990
- InterleavedAccessInfo &IAI)
981
+ InterleavedAccessInfo &IAI,
982
+ ProfileSummaryInfo *PSI, BlockFrequencyInfo *BFI)
991
983
: ScalarEpilogueStatus(SEL), TheLoop(L), PSE(PSE), LI(LI), Legal(Legal),
992
984
TTI (TTI), TLI(TLI), DB(DB), AC(AC), ORE(ORE), TheFunction(F),
993
985
Hints(Hints), InterleaveInfo(IAI) {
994
986
if (TTI.supportsScalableVectors () || ForceTargetSupportsScalableVectors)
995
987
initializeVScaleForTuning ();
996
988
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);
997
993
}
998
994
999
995
// / \return An upper bound for the vectorization factors (both fixed and
@@ -1830,6 +1826,10 @@ class LoopVectorizationCostModel {
1830
1826
1831
1827
// / The kind of cost that we are calculating
1832
1828
TTI::TargetCostKind CostKind;
1829
+
1830
+ // / Whether this loop should be optimized for size based on function attribute
1831
+ // / or profile information.
1832
+ bool OptForSize;
1833
1833
};
1834
1834
} // end namespace llvm
1835
1835
@@ -2602,9 +2602,8 @@ BasicBlock *InnerLoopVectorizer::emitSCEVChecks(BasicBlock *Bypass) {
2602
2602
if (!SCEVCheckBlock)
2603
2603
return nullptr ;
2604
2604
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) &&
2608
2607
" Cannot SCEV check stride or overflow when optimizing for size" );
2609
2608
assert (!LoopBypassBlocks.empty () &&
2610
2609
" Should already be a bypass block due to iteration count check" );
@@ -2629,7 +2628,7 @@ BasicBlock *InnerLoopVectorizer::emitMemRuntimeChecks(BasicBlock *Bypass) {
2629
2628
assert ((!EnableVPlanNativePath || OrigLoop->begin () == OrigLoop->end ()) &&
2630
2629
" Runtime checks are not supported for outer loops yet" );
2631
2630
2632
- if (MemCheckBlock-> getParent ()-> hasOptSize () || OptForSizeBasedOnProfile ) {
2631
+ if (Cost-> OptForSize ) {
2633
2632
assert (Cost->Hints ->getForce () == LoopVectorizeHints::FK_Enabled &&
2634
2633
" Cannot emit memory checks when optimizing for size, unless forced "
2635
2634
" to vectorize." );
@@ -10083,7 +10082,7 @@ static bool processLoopInVPlanNativePath(
10083
10082
getScalarEpilogueLowering (F, L, Hints, PSI, BFI, TTI, TLI, *LVL, &IAI);
10084
10083
10085
10084
LoopVectorizationCostModel CM (SEL, L, PSE, LI, LVL, *TTI, TLI, DB, AC, ORE, F,
10086
- &Hints, IAI);
10085
+ &Hints, IAI, PSI, BFI );
10087
10086
// Use the planner for outer loop vectorization.
10088
10087
// TODO: CM is not used at this point inside the planner. Turn CM into an
10089
10088
// optional argument if we don't need it in the future.
@@ -10659,7 +10658,7 @@ bool LoopVectorizePass::processLoop(Loop *L) {
10659
10658
10660
10659
// Use the cost model.
10661
10660
LoopVectorizationCostModel CM (SEL, L, PSE, LI, &LVL, *TTI, TLI, DB, AC, ORE,
10662
- F, &Hints, IAI);
10661
+ F, &Hints, IAI, PSI, BFI );
10663
10662
// Use the planner for vectorization.
10664
10663
LoopVectorizationPlanner LVP (L, LI, DT, TLI, *TTI, &LVL, CM, IAI, PSE, Hints,
10665
10664
ORE);
0 commit comments