Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions llvm/include/llvm/Analysis/LoopInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,11 @@ class LLVM_ABI Loop : public LoopBase<BasicBlock, Loop> {
};

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

/// Return true if all the operands of the specified instruction are loop
/// invariant.
bool hasLoopInvariantOperands(const Instruction *I,
bool HasCoroSuspendInst = false) const;
bool hasLoopInvariantOperands(const Instruction *I) const;

/// If the given value is an instruction inside of the loop and it can be
/// hoisted, do so to make it trivially loop-invariant.
Expand Down
3 changes: 1 addition & 2 deletions llvm/include/llvm/Transforms/Utils/LoopUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,7 @@ LLVM_ABI bool hoistRegion(DomTreeNode *, AAResults *, LoopInfo *,
TargetLibraryInfo *, Loop *, MemorySSAUpdater &,
ScalarEvolution *, ICFLoopSafetyInfo *,
SinkAndHoistLICMFlags &, OptimizationRemarkEmitter *,
bool, bool AllowSpeculation,
bool HasCoroSuspendInst = false);
bool, bool AllowSpeculation);

/// Return true if the induction variable \p IV in a Loop whose latch is
/// \p LatchBlock would become dead if the exit test \p Cond were removed.
Expand Down
22 changes: 5 additions & 17 deletions llvm/lib/Analysis/LoopInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,26 +58,14 @@ static cl::opt<bool, true>
// Loop implementation
//

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

bool Loop::hasLoopInvariantOperands(const Instruction *I,
bool HasCoroSuspendInst) const {
return all_of(I->operands(), [&](Value *V) {
return isLoopInvariant(V, HasCoroSuspendInst);
});
bool Loop::hasLoopInvariantOperands(const Instruction *I) const {
return all_of(I->operands(), [&](Value *V) { return isLoopInvariant(V); });
}

bool Loop::makeLoopInvariant(Value *V, bool &Changed, Instruction *InsertPt,
Expand Down
8 changes: 4 additions & 4 deletions llvm/lib/Transforms/Scalar/LICM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ bool LoopInvariantCodeMotion::runOnLoop(Loop *L, AAResults *AA, LoopInfo *LI,
if (Preheader)
Changed |= hoistRegion(DT->getNode(L->getHeader()), AA, LI, DT, AC, TLI, L,
MSSAU, SE, &SafetyInfo, Flags, ORE, LoopNestMode,
LicmAllowSpeculation, HasCoroSuspendInst);
LicmAllowSpeculation);

// Now that all loop invariants have been removed from the loop, promote any
// memory references to scalars that we can.
Expand Down Expand Up @@ -892,7 +892,7 @@ bool llvm::hoistRegion(DomTreeNode *N, AAResults *AA, LoopInfo *LI,
ICFLoopSafetyInfo *SafetyInfo,
SinkAndHoistLICMFlags &Flags,
OptimizationRemarkEmitter *ORE, bool LoopNestMode,
bool AllowSpeculation, bool HasCoroSuspendInst) {
bool AllowSpeculation) {
// Verify inputs.
assert(N != nullptr && AA != nullptr && LI != nullptr && DT != nullptr &&
CurLoop != nullptr && SafetyInfo != nullptr &&
Expand Down Expand Up @@ -925,7 +925,7 @@ bool llvm::hoistRegion(DomTreeNode *N, AAResults *AA, LoopInfo *LI,
// TODO: It may be safe to hoist if we are hoisting to a conditional block
// and we have accurately duplicated the control flow from the loop header
// to that block.
if (CurLoop->hasLoopInvariantOperands(&I, HasCoroSuspendInst) &&
if (CurLoop->hasLoopInvariantOperands(&I) &&
canSinkOrHoistInst(I, AA, DT, CurLoop, MSSAU, true, Flags, ORE) &&
isSafeToExecuteUnconditionally(I, DT, TLI, CurLoop, SafetyInfo, ORE,
Preheader->getTerminator(), AC,
Expand Down Expand Up @@ -975,7 +975,7 @@ bool llvm::hoistRegion(DomTreeNode *N, AAResults *AA, LoopInfo *LI,
SafetyInfo->doesNotWriteMemoryBefore(I, CurLoop);
};
if ((IsInvariantStart(I) || isGuard(&I)) &&
CurLoop->hasLoopInvariantOperands(&I, HasCoroSuspendInst) &&
CurLoop->hasLoopInvariantOperands(&I) &&
MustExecuteWithoutWritesBefore(I)) {
hoist(I, DT, CurLoop, CFH.getOrCreateHoistedBlock(BB), SafetyInfo,
MSSAU, SE, ORE);
Expand Down
78 changes: 0 additions & 78 deletions llvm/test/Transforms/LICM/licm-coroutine.ll

This file was deleted.