aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/CodeGen/CodeGenPrepare.cpp
diff options
context:
space:
mode:
authorTa-Wei Tu <tu.da.wei@gmail.com>2021-03-09 13:31:20 +0800
committerTa-Wei Tu <tu.da.wei@gmail.com>2021-03-09 13:32:34 +0800
commitcf82700af8c658ae09b14c3d01bb1e73e48d3bd3 (patch)
treedc72048bcc021c3099320585bff6013d0de3648c /llvm/lib/CodeGen/CodeGenPrepare.cpp
parent038f2a337d09e114469ddcfba5b613cdb8c0fe1d (diff)
downloadllvm-cf82700af8c658ae09b14c3d01bb1e73e48d3bd3.zip
llvm-cf82700af8c658ae09b14c3d01bb1e73e48d3bd3.tar.gz
llvm-cf82700af8c658ae09b14c3d01bb1e73e48d3bd3.tar.bz2
[CodeGenPrepare] Fix isIVIncrement (PR49466)
In the NFC commit 8d835f42a57f15c0b9053bd7c41ea95821a40e5f, the check for `!L` is moved to a separate function `getIVIncrement` which, instead of using `BO->getParent()`, uses `PN->getParent()`. However, these two basic blocks are not necessarily the same. https://bugs.llvm.org/show_bug.cgi?id=49466 demonstrates a case where `PN` is contained in a loop while `BO` is not, causing the null-pointer dereference in `L->getLoopLatch()`. This patch checks whether both `BO` and `PN` belong to the same loop before entering `getIVIncrement`. Reviewed By: mkazantsev Differential Revision: https://reviews.llvm.org/D98144
Diffstat (limited to 'llvm/lib/CodeGen/CodeGenPrepare.cpp')
-rw-r--r--llvm/lib/CodeGen/CodeGenPrepare.cpp3
1 files changed, 2 insertions, 1 deletions
diff --git a/llvm/lib/CodeGen/CodeGenPrepare.cpp b/llvm/lib/CodeGen/CodeGenPrepare.cpp
index 6e806b0..e745a37 100644
--- a/llvm/lib/CodeGen/CodeGenPrepare.cpp
+++ b/llvm/lib/CodeGen/CodeGenPrepare.cpp
@@ -1332,7 +1332,7 @@ getIVIncrement(const PHINode *PN, const LoopInfo *LI) {
static bool isIVIncrement(const BinaryOperator *BO, const LoopInfo *LI) {
auto *PN = dyn_cast<PHINode>(BO->getOperand(0));
- if (!PN)
+ if (!PN || LI->getLoopFor(BO->getParent()) != LI->getLoopFor(PN->getParent()))
return false;
if (auto IVInc = getIVIncrement(PN, LI))
return IVInc->first == BO;
@@ -1347,6 +1347,7 @@ bool CodeGenPrepare::replaceMathCmpWithIntrinsic(BinaryOperator *BO,
if (!isIVIncrement(BO, LI))
return false;
const Loop *L = LI->getLoopFor(BO->getParent());
+ assert(L && "L should not be null after isIVIncrement()");
// IV increment may have other users than the IV. We do not want to make
// dominance queries to analyze the legality of moving it towards the cmp,
// so just check that there is no other users.