Skip to content

Commit c31f558

Browse files
committed
Check the loop blocks to see if the token is referenced outside the loop
1 parent 4fc8d87 commit c31f558

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

llvm/lib/Transforms/Scalar/IndVarSimplify.cpp

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
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"
3534
#include "llvm/Analysis/LoopInfo.h"
3635
#include "llvm/Analysis/LoopPass.h"
3736
#include "llvm/Analysis/MemorySSA.h"
@@ -1860,17 +1859,19 @@ bool IndVarSimplify::predicateLoopExits(Loop *L, SCEVExpander &Rewriter) {
18601859
}
18611860
}
18621861

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-
}
1869-
1870-
if (Metrics.Convergence == ConvergenceKind::ExtendedLoop) {
1871-
// Do not predicate loops with extended convergence.
1872-
return false;
1873-
}
1862+
// Skip if the loop has tokens referenced outside the loop to avoid
1863+
// changing convergence behavior.
1864+
for (BasicBlock *Block : L->blocks()) {
1865+
for (Instruction &I : *Block) {
1866+
if (I.getType()->isTokenTy()) {
1867+
for (User *U : I.users()) {
1868+
Instruction *UserInst = dyn_cast<Instruction>(U);
1869+
if (UserInst && !L->contains(UserInst)) {
1870+
return false;
1871+
}
1872+
}
1873+
}
1874+
}
18741875

18751876
bool Changed = false;
18761877
// Finally, do the actual predication for all predicatable blocks. A couple

0 commit comments

Comments
 (0)