[LOOPGUARD] Remove asserts in getLoopGuardBranch
Summary: The assertion in getLoopGuardBranch can be a 'return nullptr'
under if condition.
Authored By: DTharun
Reviewer: Whitney, fhahn
Reviewed By: Whitney, fhahn
Subscribers: fhahn, llvm-commits
Tag: LLVM
Differential Revision: https://reviews.llvm.org/D66084
llvm-svn: 373857
diff --git a/llvm/lib/Analysis/LoopInfo.cpp b/llvm/lib/Analysis/LoopInfo.cpp
index 1dc63a3..dbab5db 100644
--- a/llvm/lib/Analysis/LoopInfo.cpp
+++ b/llvm/lib/Analysis/LoopInfo.cpp
@@ -360,11 +360,17 @@
}
BranchInst *Loop::getLoopGuardBranch() const {
- assert(isLoopSimplifyForm() && "Only valid for loop in simplify form");
+ if (!isLoopSimplifyForm())
+ return nullptr;
+
BasicBlock *Preheader = getLoopPreheader();
- assert(Preheader && getLoopLatch() &&
+ BasicBlock *Latch = getLoopLatch();
+ assert(Preheader && Latch &&
"Expecting a loop with valid preheader and latch");
- assert(isLoopExiting(getLoopLatch()) && "Only valid for rotated loop");
+
+ // Loop should be in rotate form.
+ if (!isLoopExiting(Latch))
+ return nullptr;
// Disallow loops with more than one unique exit block, as we do not verify
// that GuardOtherSucc post dominates all exit blocks.