[PATCH] D34516: [LoopDeletion] Update exits correctly when multiple duplicate edges from an exiting block

Eli Friedman via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 22 12:56:39 PDT 2017


efriedma accepted this revision.
efriedma added a comment.
This revision is now accepted and ready to land.

LGTM with the comment fixed.



================
Comment at: lib/Transforms/Scalar/LoopDeletion.cpp:250
     if (LoopIsNeverExecuted)
-      P->setIncomingValue(j, UndefValue::get(P->getType()));
-    P->setIncomingBlock(j, Preheader);
-    for (unsigned i = 1; i < ExitingBlocks.size(); ++i)
-      P->removeIncomingValue(ExitingBlocks[i]);
+      P->setIncomingValue(PredIndex, UndefValue::get(P->getType()));
+    P->setIncomingBlock(PredIndex, Preheader);
----------------
anna wrote:
> efriedma wrote:
> > Do you need to call setIncomingValue() in the case where LoopIsNeverExecuted is false?
> We don't need to. When LoopIsNeverExecuted is false, all the exiting blocks have the same 'value', which gets moved to the preheader. This is also the reason why in the original implementation (before this patch), we keep just one exiting block and remove all others. 
> 
> As a follow-on NFC, I'm going to move this undef value setting into a prepass before calling this function `deleteDeadLoop`.
Okay, that makes sense.


https://reviews.llvm.org/D34516





More information about the llvm-commits mailing list