diff --git a/llvm/lib/Transforms/InstCombine/InstCombineInternal.h b/llvm/lib/Transforms/InstCombine/InstCombineInternal.h index 2486be77ebabb..0f2e516e2f91b 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineInternal.h +++ b/llvm/lib/Transforms/InstCombine/InstCombineInternal.h @@ -653,6 +653,8 @@ class LLVM_LIBRARY_VISIBILITY InstCombinerImpl final Instruction *SimplifyAnyMemSet(AnyMemSetInst *MI); Value *EvaluateInDifferentType(Value *V, Type *Ty, bool isSigned); + + bool tryToSinkInstruction(Instruction *I, BasicBlock *DestBlock); }; class Negator final { diff --git a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp index b1f4e9f8e4f26..8c10fe96aaf85 100644 --- a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp +++ b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp @@ -3475,8 +3475,8 @@ static bool SoleWriteToDeadLocal(Instruction *I, TargetLibraryInfo &TLI) { /// beginning of DestBlock, which can only happen if it's safe to move the /// instruction past all of the instructions between it and the end of its /// block. -static bool TryToSinkInstruction(Instruction *I, BasicBlock *DestBlock, - TargetLibraryInfo &TLI) { +bool InstCombinerImpl::tryToSinkInstruction(Instruction *I, + BasicBlock *DestBlock) { BasicBlock *SrcBlock = I->getParent(); // Cannot move control-flow-involving, volatile loads, vaarg, etc. @@ -3523,10 +3523,13 @@ static bool TryToSinkInstruction(Instruction *I, BasicBlock *DestBlock, return false; } - I->dropDroppableUses([DestBlock](const Use *U) { - if (auto *I = dyn_cast(U->getUser())) - return I->getParent() != DestBlock; - return true; + I->dropDroppableUses([&](const Use *U) { + auto *I = dyn_cast(U->getUser()); + if (I && I->getParent() != DestBlock) { + Worklist.add(I); + return true; + } + return false; }); /// FIXME: We could remove droppable uses that are not dominated by /// the new position. @@ -3699,7 +3702,7 @@ bool InstCombinerImpl::run() { if (OptBB) { auto *UserParent = *OptBB; // Okay, the CFG is simple enough, try to sink this instruction. - if (TryToSinkInstruction(I, UserParent, TLI)) { + if (tryToSinkInstruction(I, UserParent)) { LLVM_DEBUG(dbgs() << "IC: Sink: " << *I << '\n'); MadeIRChange = true; // We'll add uses of the sunk instruction below, but since