From 39ac159c24b5c0ae37506d1588321bebf429c973 Mon Sep 17 00:00:00 2001 From: John Brawn Date: Fri, 4 Jan 2019 17:12:09 +0000 Subject: [LICM] Adjust how moving the re-hoist point works In some cases the order that we hoist instructions in means that when rehoisting (which uses the same order as hoisting) we can rehoist to a block A, then a block B, then block A again. This currently causes an assertion failure as it expects that when changing the hoist point it only ever moves to a block that dominates the hoist point being moved from. Fix this by moving the re-hoist point when it doesn't dominate the dominator of hoisted instruction, or in other words when it wouldn't dominate the uses of the instruction being rehoisted. Differential Revision: https://reviews.llvm.org/D55266 llvm-svn: 350408 --- llvm/lib/Transforms/Scalar/LICM.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'llvm/lib/Transforms/Scalar/LICM.cpp') diff --git a/llvm/lib/Transforms/Scalar/LICM.cpp b/llvm/lib/Transforms/Scalar/LICM.cpp index 695eaf6cf4a..5ebf035bf51 100644 --- a/llvm/lib/Transforms/Scalar/LICM.cpp +++ b/llvm/lib/Transforms/Scalar/LICM.cpp @@ -809,14 +809,15 @@ bool llvm::hoistRegion(DomTreeNode *N, AliasAnalysis *AA, LoopInfo *LI, [&](Use &U) { return DT->dominates(I, U); })) { BasicBlock *Dominator = DT->getNode(I->getParent())->getIDom()->getBlock(); - LLVM_DEBUG(dbgs() << "LICM rehoisting to " << Dominator->getName() - << ": " << *I << "\n"); - if (!HoistPoint || HoistPoint->getParent() != Dominator) { + if (!HoistPoint || !DT->dominates(HoistPoint->getParent(), Dominator)) { if (HoistPoint) assert(DT->dominates(Dominator, HoistPoint->getParent()) && "New hoist point expected to dominate old hoist point"); HoistPoint = Dominator->getTerminator(); } + LLVM_DEBUG(dbgs() << "LICM rehoisting to " + << HoistPoint->getParent()->getName() + << ": " << *I << "\n"); moveInstructionBefore(*I, *HoistPoint, *SafetyInfo); HoistPoint = I; Changed = true; -- cgit v1.2.3