Skip to content

Commit 4fc8d87

Browse files
committed
Use helper
1 parent e01b798 commit 4fc8d87

File tree

1 file changed

+10
-28
lines changed

1 file changed

+10
-28
lines changed

llvm/lib/Transforms/Scalar/IndVarSimplify.cpp

Lines changed: 10 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include "llvm/ADT/SmallVector.h"
3232
#include "llvm/ADT/Statistic.h"
3333
#include "llvm/ADT/iterator_range.h"
34+
#include "llvm/Analysis/CodeMetrics.h"
3435
#include "llvm/Analysis/LoopInfo.h"
3536
#include "llvm/Analysis/LoopPass.h"
3637
#include "llvm/Analysis/MemorySSA.h"
@@ -1859,35 +1860,16 @@ bool IndVarSimplify::predicateLoopExits(Loop *L, SCEVExpander &Rewriter) {
18591860
}
18601861
}
18611862

1862-
// If the loop body uses a convergence token defined within the loop, skip
1863-
// predication. This is to avoid changing the convergence behavior of the
1864-
// loop.
1865-
SmallVector<BasicBlock *, 16> blocks = ExitingBlocks;
1866-
SmallVector<Value *, 16> tokens = {};
1867-
size_t index = 0; // Assume Exiting Blocks are sorted.
1868-
while (index < blocks.size()) {
1869-
BasicBlock *BB = blocks[index];
1870-
index++;
1871-
const auto exitingBlockName = BB->getName();
1872-
for (Instruction &I : *BB) {
1873-
// Check if the instruction uses any convergence tokens.
1874-
if (auto *CB = dyn_cast<CallBase>(&I);
1875-
CB && !isa<ConvergenceControlInst>(&I)) {
1876-
auto token = CB->getConvergenceControlToken();
1877-
if (token && llvm::is_contained(tokens, token)) {
1878-
return false;
1879-
}
1880-
}
1881-
if (isa<ConvergenceControlInst>(&I)) {
1882-
tokens.push_back(cast<Value>(&I));
1883-
}
1884-
}
1863+
CodeMetrics Metrics;
1864+
SmallPtrSet<const Value *, 32> EphValues;
1865+
for (BasicBlock *BB : L->blocks()) {
1866+
Metrics.analyzeBasicBlock(BB, *TTI, EphValues, /* PrepareForLTO= */ false,
1867+
L);
1868+
}
18851869

1886-
for (BasicBlock *Succ : successors(BB)) {
1887-
const auto succName = Succ->getName();
1888-
if (Succ != L->getLoopLatch() && !llvm::is_contained(blocks, Succ))
1889-
blocks.push_back(Succ);
1890-
}
1870+
if (Metrics.Convergence == ConvergenceKind::ExtendedLoop) {
1871+
// Do not predicate loops with extended convergence.
1872+
return false;
18911873
}
18921874

18931875
bool Changed = false;

0 commit comments

Comments
 (0)