diff --git a/llvm/include/llvm/Transforms/Utils/CodeMoverUtils.h b/llvm/include/llvm/Transforms/Utils/CodeMoverUtils.h --- a/llvm/include/llvm/Transforms/Utils/CodeMoverUtils.h +++ b/llvm/include/llvm/Transforms/Utils/CodeMoverUtils.h @@ -36,6 +36,11 @@ const DominatorTree &DT, const PostDominatorTree &PDT); +/// Return true if \p I can be safely moved before \p InsertPoint. +bool isSafeToMoveBefore(Instruction &I, Instruction &InsertPoint, + DominatorTree &DT, bool skipControlFlowEquivalence, + DependenceInfo *DI = nullptr); + /// Return true if \p I can be safely moved before \p InsertPoint. bool isSafeToMoveBefore(Instruction &I, Instruction &InsertPoint, DominatorTree &DT, diff --git a/llvm/lib/Transforms/Utils/CodeMoverUtils.cpp b/llvm/lib/Transforms/Utils/CodeMoverUtils.cpp --- a/llvm/lib/Transforms/Utils/CodeMoverUtils.cpp +++ b/llvm/lib/Transforms/Utils/CodeMoverUtils.cpp @@ -306,12 +306,21 @@ getNextInsts(*CurInst, WorkList); } } - bool llvm::isSafeToMoveBefore(Instruction &I, Instruction &InsertPoint, DominatorTree &DT, const PostDominatorTree *PDT, DependenceInfo *DI) { - // Skip tests when we don't have PDT or DI - if (!PDT || !DI) + // TODO remove this limitation. + if (!isControlFlowEquivalent(I, InsertPoint, DT, *PDT)) + return reportInvalidCandidate(I, NotControlFlowEquivalent); + return isSafeToMoveBefore(I, InsertPoint, DT, true, DI); +} + +bool llvm::isSafeToMoveBefore(Instruction &I, Instruction &InsertPoint, + DominatorTree &DT, + bool skipControlFlowEquivalence, + DependenceInfo *DI) { + // Skip tests when we don't have DI + if (!skipControlFlowEquivalence || !DI) return false; // Cannot move itself before itself. @@ -328,10 +337,6 @@ if (I.isTerminator()) return reportInvalidCandidate(I, NotMovedTerminator); - // TODO remove this limitation. - if (!isControlFlowEquivalent(I, InsertPoint, DT, *PDT)) - return reportInvalidCandidate(I, NotControlFlowEquivalent); - if (!DT.dominates(&InsertPoint, &I)) for (const Use &U : I.uses()) if (auto *UserInst = dyn_cast(U.getUser()))