aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Transforms/Utils/LoopVersioning.cpp
diff options
context:
space:
mode:
authorYueh-Ting Chen <yueh.ting.chen@gmail.com>2021-12-16 00:26:20 -0800
committereopXD <eop.chen@sifive.com>2021-12-16 00:41:29 -0800
commitfbf6c8ac1589a4be68ee549257f1d528937ac582 (patch)
tree144d383f325a1dc0f3ac84cfebffcfd35e33891e /llvm/lib/Transforms/Utils/LoopVersioning.cpp
parent68cb111f3a5802f9319f7343dd1838e4fb76f004 (diff)
downloadllvm-fbf6c8ac1589a4be68ee549257f1d528937ac582.zip
llvm-fbf6c8ac1589a4be68ee549257f1d528937ac582.tar.gz
llvm-fbf6c8ac1589a4be68ee549257f1d528937ac582.tar.bz2
[LoopVersioning] Allow versionLoop to create plain branch inst when no runtime check is specified
After this function call, the LLVM IR would look like the following: ``` if (true) /* NonVersionedLoop */ else /* VersionedLoop */ ``` Reviewed By: Whitney Differential Revision: https://reviews.llvm.org/D104631
Diffstat (limited to 'llvm/lib/Transforms/Utils/LoopVersioning.cpp')
-rw-r--r--llvm/lib/Transforms/Utils/LoopVersioning.cpp20
1 files changed, 13 insertions, 7 deletions
diff --git a/llvm/lib/Transforms/Utils/LoopVersioning.cpp b/llvm/lib/Transforms/Utils/LoopVersioning.cpp
index 771b7d2..15a40ca 100644
--- a/llvm/lib/Transforms/Utils/LoopVersioning.cpp
+++ b/llvm/lib/Transforms/Utils/LoopVersioning.cpp
@@ -30,6 +30,9 @@
using namespace llvm;
+#define LVER_OPTION "loop-versioning"
+#define DEBUG_TYPE LVER_OPTION
+
static cl::opt<bool>
AnnotateNoAlias("loop-version-annotate-no-alias", cl::init(true),
cl::Hidden,
@@ -84,8 +87,11 @@ void LoopVersioning::versionLoop(
} else
RuntimeCheck = MemRuntimeCheck ? MemRuntimeCheck : SCEVRuntimeCheck;
- assert(RuntimeCheck && "called even though we don't need "
- "any runtime checks");
+ if (!RuntimeCheck) {
+ LLVM_DEBUG(dbgs() << DEBUG_TYPE " No MemRuntimeCheck or SCEVRuntimeCheck found"
+ << ", set RuntimeCheck to False\n");
+ RuntimeCheck = ConstantInt::getFalse(RuntimeCheckBB->getContext());
+ }
// Rename the block to make the IR more readable.
RuntimeCheckBB->setName(VersionedLoop->getHeader()->getName() +
@@ -109,8 +115,8 @@ void LoopVersioning::versionLoop(
// Insert the conditional branch based on the result of the memchecks.
Instruction *OrigTerm = RuntimeCheckBB->getTerminator();
- BranchInst::Create(NonVersionedLoop->getLoopPreheader(),
- VersionedLoop->getLoopPreheader(), RuntimeCheck, OrigTerm);
+ RuntimeCheckBI = BranchInst::Create(NonVersionedLoop->getLoopPreheader(),
+ VersionedLoop->getLoopPreheader(), RuntimeCheck, OrigTerm);
OrigTerm->eraseFromParent();
// The loops merge in the original exit block. This is now dominated by the
@@ -125,6 +131,9 @@ void LoopVersioning::versionLoop(
assert(NonVersionedLoop->isLoopSimplifyForm() &&
VersionedLoop->isLoopSimplifyForm() &&
"The versioned loops should be in simplify form.");
+
+ // RuntimeCheckBB and RuntimeCheckBI is recorded
+ assert(RuntimeCheckBB && RuntimeCheckBI);
}
void LoopVersioning::addPHINodes(
@@ -324,9 +333,6 @@ public:
};
}
-#define LVER_OPTION "loop-versioning"
-#define DEBUG_TYPE LVER_OPTION
-
char LoopVersioningLegacyPass::ID;
static const char LVer_name[] = "Loop Versioning";