Skip to content

Commit 813d693

Browse files
committed
Address review comments
* Renamed CountableEarlyExitBlocks -> CountableEarlyExitingBlocks * Renamed getExactExitingBlocks -> getCountableExitingBlocks * Updated comments in code. * Improved analysis/debug message. * Simplified code in isAnalyzableEarlyExitLoop and BackedgeTakenInfo::getSpeculative.
1 parent 9347bf4 commit 813d693

File tree

7 files changed

+23
-31
lines changed

7 files changed

+23
-31
lines changed

llvm/include/llvm/Analysis/LoopAccessAnalysis.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,7 @@ class LoopAccessInfo {
626626
/// Returns all blocks with a countable exit, i.e. the exit-not-taken count
627627
/// is known exactly at compile time.
628628
const SmallVector<BasicBlock *, 4> &getCountableEarlyExitingBlocks() const {
629-
return CountableEarlyExitBlocks;
629+
return CountableEarlyExitingBlocks;
630630
}
631631

632632
/// The diagnostics report generated for the analysis. E.g. why we
@@ -731,7 +731,7 @@ class LoopAccessInfo {
731731

732732
/// Keeps track of all the early exits with known or countable exit-not-taken
733733
/// counts.
734-
SmallVector<BasicBlock *, 4> CountableEarlyExitBlocks;
734+
SmallVector<BasicBlock *, 4> CountableEarlyExitingBlocks;
735735

736736
/// Indicator that there are non vectorizable stores to a uniform address.
737737
bool HasDependenceInvolvingLoopInvariantAddress = false;

llvm/include/llvm/Analysis/ScalarEvolution.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -917,9 +917,9 @@ class ScalarEvolution {
917917
}
918918

919919
/// Return all the exiting blocks in with exact exit counts.
920-
void getExactExitingBlocks(const Loop *L,
921-
SmallVector<BasicBlock *, 4> *Blocks) {
922-
getBackedgeTakenInfo(L).getExactExitingBlocks(L, this, Blocks);
920+
void getCountableExitingBlocks(const Loop *L,
921+
SmallVector<BasicBlock *, 4> *Blocks) {
922+
getBackedgeTakenInfo(L).getCountableExitingBlocks(L, this, Blocks);
923923
}
924924

925925
/// Return true if the backedge taken count is either the value returned by
@@ -1562,8 +1562,8 @@ class ScalarEvolution {
15621562
ScalarEvolution *SE) const;
15631563

15641564
/// Return all the exiting blocks in with exact exit counts.
1565-
void getExactExitingBlocks(const Loop *L, ScalarEvolution *SE,
1566-
SmallVector<BasicBlock *, 4> *Blocks) const;
1565+
void getCountableExitingBlocks(const Loop *L, ScalarEvolution *SE,
1566+
SmallVector<BasicBlock *, 4> *Blocks) const;
15671567

15681568
/// Get the constant max backedge taken count for the loop.
15691569
const SCEV *getConstantMax(ScalarEvolution *SE) const;

llvm/include/llvm/Support/GenericLoopInfo.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,8 +294,8 @@ template <class BlockT, class LoopT> class LoopBase {
294294
/// Otherwise return null.
295295
BlockT *getUniqueExitBlock() const;
296296

297-
/// Return the exit block for the latch if one exists. This function assumes
298-
/// the loop has a latch.
297+
/// Return the exit block for the latch. This function assumes the loop has a
298+
/// single latch.
299299
BlockT *getLatchExitBlock() const;
300300

301301
/// Return true if this loop does not have any exit blocks.

llvm/lib/Analysis/LoopAccessAnalysis.cpp

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2419,25 +2419,19 @@ bool LoopAccessInfo::isAnalyzableEarlyExitLoop() {
24192419
if (ExitingBlocks.size() < 2)
24202420
return false;
24212421

2422-
SmallVector<BasicBlock *, 4> ExactExitingBlocks;
2423-
PSE->getSE()->getExactExitingBlocks(TheLoop, &ExactExitingBlocks);
2422+
SmallVector<BasicBlock *, 4> CountableExitingBBs;
2423+
PSE->getSE()->getCountableExitingBlocks(TheLoop, &CountableExitingBBs);
24242424

24252425
// We only support one speculative early exit.
2426-
if ((ExitingBlocks.size() - ExactExitingBlocks.size()) > 1)
2426+
if ((ExitingBlocks.size() - CountableExitingBBs.size()) > 1)
24272427
return false;
24282428

24292429
// There could be multiple exiting blocks with an exact exit-not-taken
24302430
// count. Find the speculative early exit block, i.e. the one with an
24312431
// unknown count.
24322432
BasicBlock *TmpBB = nullptr;
24332433
for (BasicBlock *BB1 : ExitingBlocks) {
2434-
bool Found = false;
2435-
for (BasicBlock *BB2 : ExactExitingBlocks)
2436-
if (BB1 == BB2) {
2437-
Found = true;
2438-
break;
2439-
}
2440-
if (!Found) {
2434+
if (!is_contained(CountableExitingBBs, BB1)) {
24412435
TmpBB = BB1;
24422436
break;
24432437
}
@@ -2468,7 +2462,7 @@ bool LoopAccessInfo::isAnalyzableEarlyExitLoop() {
24682462
}
24692463
assert(SpeculativeEarlyExitBB &&
24702464
"Expected to find speculative early exit block");
2471-
CountableEarlyExitBlocks = std::move(ExactExitingBlocks);
2465+
CountableEarlyExitingBlocks = std::move(CountableExitingBBs);
24722466

24732467
return true;
24742468
}
@@ -2626,9 +2620,11 @@ void LoopAccessInfo::analyzeLoop(AAResults *AA, LoopInfo *LI,
26262620
if (I.mayWriteToMemory()) {
26272621
auto *St = dyn_cast<StoreInst>(&I);
26282622
if (SpeculativeEarlyExitingBB) {
2629-
recordAnalysis("CantVectorizeInstruction", St)
2630-
<< "cannot vectorize stores in early exit loop";
2631-
LLVM_DEBUG(dbgs() << "LAA: Found a store in early exit loop.\n");
2623+
recordAnalysis("CantVectorizeInstruction", &I)
2624+
<< "cannot vectorize instructions that write to memory in early "
2625+
<< "exit loop";
2626+
LLVM_DEBUG(dbgs() << "LAA: Found an instruction that writes to "
2627+
<< "memory in early exit loop.\n");
26322628
HasComplexWorkInEarlyExitLoop = true;
26332629
continue;
26342630
}
@@ -2784,7 +2780,6 @@ void LoopAccessInfo::analyzeLoop(AAResults *AA, LoopInfo *LI,
27842780
Accesses.buildDependenceSets();
27852781

27862782
if (SpeculativeEarlyExitingBB) {
2787-
assert(!Stores.size() && "Did not expect stores in an early exit loop!");
27882783
LoopMayFault = Accesses.mayFault();
27892784
CanVecMem = true;
27902785
return;

llvm/lib/Analysis/ScalarEvolution.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8602,7 +8602,7 @@ ScalarEvolution::BackedgeTakenInfo::getExact(const Loop *L, ScalarEvolution *SE,
86028602
return SE->getUMinFromMismatchedTypes(Ops, /* Sequential */ true);
86038603
}
86048604

8605-
void ScalarEvolution::BackedgeTakenInfo::getExactExitingBlocks(
8605+
void ScalarEvolution::BackedgeTakenInfo::getCountableExitingBlocks(
86068606
const Loop *L, ScalarEvolution *SE,
86078607
SmallVector<BasicBlock *, 4> *Blocks) const {
86088608
// All exiting blocks we have collected must dominate the only backedge.
@@ -8625,10 +8625,7 @@ const SCEV *ScalarEvolution::BackedgeTakenInfo::getSpeculative(
86258625
SmallVector<const SCEVPredicate *, 4> *Preds) const {
86268626
// All exiting blocks we have collected must dominate the only backedge.
86278627
const BasicBlock *Latch = L->getLoopLatch();
8628-
if (!Latch)
8629-
return SE->getCouldNotCompute();
8630-
8631-
if (!hasAnyInfo())
8628+
if (!Latch || !hasAnyInfo())
86328629
return SE->getCouldNotCompute();
86338630

86348631
// All exiting blocks we have gathered dominate loop's latch, so speculative

llvm/lib/Transforms/Vectorize/VPlan.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2962,7 +2962,7 @@ class VPRegionBlock : public VPBlockBase {
29622962
/// VPRegionBlock.
29632963
VPBlockBase *Exiting;
29642964

2965-
/// Hold the Early Exiting block of the SEME region, if one exists.
2965+
/// Hold the Early Exit block of the SEME region, if one exists.
29662966
VPBlockBase *EarlyExit;
29672967

29682968
/// We need to keep track of the early exit block from the original scalar

llvm/test/Transforms/LoopVectorize/control-flow.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
; return 0;
1111
; }
1212

13-
; CHECK: remark: source.cpp:8:7: loop not vectorized: cannot vectorize stores in early exit loop
13+
; CHECK: remark: source.cpp:8:7: loop not vectorized: cannot vectorize instructions that write to memory in early exit loop
1414
; CHECK: remark: source.cpp:5:9: loop not vectorized
1515

1616
; CHECK: _Z4testPii

0 commit comments

Comments
 (0)