[llvm] r297016 - [BasicBlockUtils] Check for nullptr before updating LoopInfo.

Michael Kruse via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 6 07:33:05 PST 2017


Author: meinersbur
Date: Mon Mar  6 09:33:05 2017
New Revision: 297016

URL: http://llvm.org/viewvc/llvm-project?rev=297016&view=rev
Log:
[BasicBlockUtils] Check for nullptr before updating LoopInfo.

LoopInfo::getLoopFor returns nullptr if a BB is not in a loop and only
then can the loop be updated to contain the newly created BBs. Add the
missing nullptr check to SplitBlockAndInsertIfThen.

Within LLVM, the only user of this function that also passes a LoopInfo
to be updated is InnerLoopVectorizer::predicateInstructions().
As the method's name implies, the BB operataten on will always be within
a loop, but out-of-tree users may also use it differently (here: Polly).

All other uses of LoopInfo::getLoopFor in the file properly check its
return value for nullptr.

Modified:
    llvm/trunk/lib/Transforms/Utils/BasicBlockUtils.cpp

Modified: llvm/trunk/lib/Transforms/Utils/BasicBlockUtils.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/BasicBlockUtils.cpp?rev=297016&r1=297015&r2=297016&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/BasicBlockUtils.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/BasicBlockUtils.cpp Mon Mar  6 09:33:05 2017
@@ -646,9 +646,10 @@ llvm::SplitBlockAndInsertIfThen(Value *C
   }
 
   if (LI) {
-    Loop *L = LI->getLoopFor(Head);
-    L->addBasicBlockToLoop(ThenBlock, *LI);
-    L->addBasicBlockToLoop(Tail, *LI);
+    if (Loop *L = LI->getLoopFor(Head)) {
+      L->addBasicBlockToLoop(ThenBlock, *LI);
+      L->addBasicBlockToLoop(Tail, *LI);
+    }
   }
 
   return CheckTerm;




More information about the llvm-commits mailing list