[PATCH] D51486: Add check to Latch's terminator in UnrollRuntimeLoopRemainder
Rodrigo Caetano Rocha via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 30 06:17:40 PDT 2018
rcorcs created this revision.
rcorcs added a reviewer: hfinkel.
Herald added subscribers: llvm-commits, dmgreen, zzheng.
In this patch, I'm adding an extra check to the Latch's terminator in llvm::UnrollRuntimeLoopRemainder,
similar to how it is already done in the llvm::UnrollLoop.
The compiler would crash if this function is called with a malformed loop.
Repository:
rL LLVM
https://reviews.llvm.org/D51486
Files:
lib/Transforms/Utils/LoopUnrollRuntime.cpp
Index: lib/Transforms/Utils/LoopUnrollRuntime.cpp
===================================================================
--- lib/Transforms/Utils/LoopUnrollRuntime.cpp
+++ lib/Transforms/Utils/LoopUnrollRuntime.cpp
@@ -545,6 +545,15 @@
BasicBlock *Header = L->getHeader();
BranchInst *LatchBR = cast<BranchInst>(Latch->getTerminator());
+
+ if (!LatchBR || LatchBR->isUnconditional()) {
+ // The loop-rotate pass can be helpful to avoid this in many cases.
+ LLVM_DEBUG(
+ dbgs()
+ << "Can't unroll; loop not terminated by a conditional branch.\n");
+ return false;
+ }
+
unsigned ExitIndex = LatchBR->getSuccessor(0) == Header ? 1 : 0;
BasicBlock *LatchExit = LatchBR->getSuccessor(ExitIndex);
// Cloning the loop basic blocks (`CloneLoopBlocks`) requires that one of the
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D51486.163314.patch
Type: text/x-patch
Size: 812 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180830/60023784/attachment.bin>
More information about the llvm-commits
mailing list