[runtimeunroll] Fix reported DT verification error after 94d0914
authorPhilip Reames <listmail@philipreames.com>
Thu, 19 Aug 2021 18:04:31 +0000 (11:04 -0700)
committerPhilip Reames <listmail@philipreames.com>
Thu, 19 Aug 2021 18:06:17 +0000 (11:06 -0700)
In 94d0914, I added support for unrolling of multiple exit loops which have multiple exits reaching the latch.  Per reports on the review post commit, I'd missed updating the domtree for one case.  This fix addresses that ommission.

There's no new test as this is covered by existing tests with expensive verification turned on.

llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp

index 0bad348..cd86552 100644 (file)
@@ -285,8 +285,10 @@ static void ConnectEpilog(Loop *L, Value *ModVal, BasicBlock *NewExit,
   // Add the branch to the exit block (around the unrolling loop)
   B.CreateCondBr(BrLoopExit, EpilogPreHeader, Exit);
   InsertPt->eraseFromParent();
-  if (DT)
-    DT->changeImmediateDominator(Exit, NewExit);
+  if (DT) {
+    auto *NewDom = DT->findNearestCommonDominator(Exit, NewExit);
+    DT->changeImmediateDominator(Exit, NewDom);
+  }
 
   // Split the main loop exit to maintain canonicalization guarantees.
   SmallVector<BasicBlock*, 4> NewExitPreds{Latch};