Skip to content

Commit 1329af9

Browse files
authored
Revert "[LoopInfo] Pointer to stack object may not be loop invariant in a coroutine function (#149936)" (#157986)
Since #156788 has resolved #149604, we can revert this workaround now.
1 parent 3ade874 commit 1329af9

File tree

5 files changed

+12
-104
lines changed

5 files changed

+12
-104
lines changed

llvm/include/llvm/Analysis/LoopInfo.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,11 @@ class LLVM_ABI Loop : public LoopBase<BasicBlock, Loop> {
5959
};
6060

6161
/// Return true if the specified value is loop invariant.
62-
bool isLoopInvariant(const Value *V, bool HasCoroSuspendInst = false) const;
62+
bool isLoopInvariant(const Value *V) const;
6363

6464
/// Return true if all the operands of the specified instruction are loop
6565
/// invariant.
66-
bool hasLoopInvariantOperands(const Instruction *I,
67-
bool HasCoroSuspendInst = false) const;
66+
bool hasLoopInvariantOperands(const Instruction *I) const;
6867

6968
/// If the given value is an instruction inside of the loop and it can be
7069
/// hoisted, do so to make it trivially loop-invariant.

llvm/include/llvm/Transforms/Utils/LoopUtils.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,7 @@ LLVM_ABI bool hoistRegion(DomTreeNode *, AAResults *, LoopInfo *,
185185
TargetLibraryInfo *, Loop *, MemorySSAUpdater &,
186186
ScalarEvolution *, ICFLoopSafetyInfo *,
187187
SinkAndHoistLICMFlags &, OptimizationRemarkEmitter *,
188-
bool, bool AllowSpeculation,
189-
bool HasCoroSuspendInst = false);
188+
bool, bool AllowSpeculation);
190189

191190
/// Return true if the induction variable \p IV in a Loop whose latch is
192191
/// \p LatchBlock would become dead if the exit test \p Cond were removed.

llvm/lib/Analysis/LoopInfo.cpp

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -58,26 +58,14 @@ static cl::opt<bool, true>
5858
// Loop implementation
5959
//
6060

61-
bool Loop::isLoopInvariant(const Value *V, bool HasCoroSuspendInst) const {
62-
if (const Instruction *I = dyn_cast<Instruction>(V)) {
63-
// FIXME: this is semantically inconsistent. We're tracking a proper fix in
64-
// issue #149604.
65-
// If V is a pointer to stack object and L contains a coro.suspend function
66-
// call, then V may not be loop invariant because the ramp function and
67-
// resume function have different stack frames.
68-
if (HasCoroSuspendInst && isa<AllocaInst>(I))
69-
return false;
70-
else
71-
return !contains(I);
72-
}
61+
bool Loop::isLoopInvariant(const Value *V) const {
62+
if (const Instruction *I = dyn_cast<Instruction>(V))
63+
return !contains(I);
7364
return true; // All non-instructions are loop invariant
7465
}
7566

76-
bool Loop::hasLoopInvariantOperands(const Instruction *I,
77-
bool HasCoroSuspendInst) const {
78-
return all_of(I->operands(), [&](Value *V) {
79-
return isLoopInvariant(V, HasCoroSuspendInst);
80-
});
67+
bool Loop::hasLoopInvariantOperands(const Instruction *I) const {
68+
return all_of(I->operands(), [&](Value *V) { return isLoopInvariant(V); });
8169
}
8270

8371
bool Loop::makeLoopInvariant(Value *V, bool &Changed, Instruction *InsertPt,

llvm/lib/Transforms/Scalar/LICM.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ bool LoopInvariantCodeMotion::runOnLoop(Loop *L, AAResults *AA, LoopInfo *LI,
474474
if (Preheader)
475475
Changed |= hoistRegion(DT->getNode(L->getHeader()), AA, LI, DT, AC, TLI, L,
476476
MSSAU, SE, &SafetyInfo, Flags, ORE, LoopNestMode,
477-
LicmAllowSpeculation, HasCoroSuspendInst);
477+
LicmAllowSpeculation);
478478

479479
// Now that all loop invariants have been removed from the loop, promote any
480480
// memory references to scalars that we can.
@@ -892,7 +892,7 @@ bool llvm::hoistRegion(DomTreeNode *N, AAResults *AA, LoopInfo *LI,
892892
ICFLoopSafetyInfo *SafetyInfo,
893893
SinkAndHoistLICMFlags &Flags,
894894
OptimizationRemarkEmitter *ORE, bool LoopNestMode,
895-
bool AllowSpeculation, bool HasCoroSuspendInst) {
895+
bool AllowSpeculation) {
896896
// Verify inputs.
897897
assert(N != nullptr && AA != nullptr && LI != nullptr && DT != nullptr &&
898898
CurLoop != nullptr && SafetyInfo != nullptr &&
@@ -925,7 +925,7 @@ bool llvm::hoistRegion(DomTreeNode *N, AAResults *AA, LoopInfo *LI,
925925
// TODO: It may be safe to hoist if we are hoisting to a conditional block
926926
// and we have accurately duplicated the control flow from the loop header
927927
// to that block.
928-
if (CurLoop->hasLoopInvariantOperands(&I, HasCoroSuspendInst) &&
928+
if (CurLoop->hasLoopInvariantOperands(&I) &&
929929
canSinkOrHoistInst(I, AA, DT, CurLoop, MSSAU, true, Flags, ORE) &&
930930
isSafeToExecuteUnconditionally(I, DT, TLI, CurLoop, SafetyInfo, ORE,
931931
Preheader->getTerminator(), AC,
@@ -975,7 +975,7 @@ bool llvm::hoistRegion(DomTreeNode *N, AAResults *AA, LoopInfo *LI,
975975
SafetyInfo->doesNotWriteMemoryBefore(I, CurLoop);
976976
};
977977
if ((IsInvariantStart(I) || isGuard(&I)) &&
978-
CurLoop->hasLoopInvariantOperands(&I, HasCoroSuspendInst) &&
978+
CurLoop->hasLoopInvariantOperands(&I) &&
979979
MustExecuteWithoutWritesBefore(I)) {
980980
hoist(I, DT, CurLoop, CFH.getOrCreateHoistedBlock(BB), SafetyInfo,
981981
MSSAU, SE, ORE);

llvm/test/Transforms/LICM/licm-coroutine.ll

Lines changed: 0 additions & 78 deletions
This file was deleted.

0 commit comments

Comments
 (0)