summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms
diff options
context:
space:
mode:
authorXin Tong <trent.xin.tong@gmail.com>2018-02-28 12:08:00 +0000
committerXin Tong <trent.xin.tong@gmail.com>2018-02-28 12:08:00 +0000
commit8ba674e43b5d907f2a0e3f651731232b7624c7df (patch)
tree0b66103d76ba4cfb5756902e271833328863e49e /llvm/lib/Transforms
parent60f57369a2199a91a985a88a00703caa454f2363 (diff)
downloadbcm5719-llvm-8ba674e43b5d907f2a0e3f651731232b7624c7df.tar.gz
bcm5719-llvm-8ba674e43b5d907f2a0e3f651731232b7624c7df.zip
[MergeICmp] Fix a bug in MergeICmp that can lead to a block being processed more than once.
Summary: Fix a bug in MergeICmp that can lead to a BCECmp block being processed more than once and eventually lead to a broken LLVM module. The problem is that if the non-constant value is not produced by the last block, the producer will be processed once when the its parent block is processed and second time when the last block is processed. We end up having 2 same BCECmpBlock in the merge queue. And eventually lead to a broken LLVM module. Reviewers: courbet, davide Reviewed By: courbet Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D43825 llvm-svn: 326318
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r--llvm/lib/Transforms/Scalar/MergeICmps.cpp13
1 files changed, 13 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/Scalar/MergeICmps.cpp b/llvm/lib/Transforms/Scalar/MergeICmps.cpp
index 745d29d14dd..3e695127d3a 100644
--- a/llvm/lib/Transforms/Scalar/MergeICmps.cpp
+++ b/llvm/lib/Transforms/Scalar/MergeICmps.cpp
@@ -571,6 +571,19 @@ bool processPhi(PHINode &Phi, const TargetLibraryInfo *const TLI) {
DEBUG(dbgs() << "skip: several non-constant values\n");
return false;
}
+ if (!isa<ICmpInst>(Phi.getIncomingValue(I)) ||
+ cast<ICmpInst>(Phi.getIncomingValue(I))->getParent() !=
+ Phi.getIncomingBlock(I)) {
+ // Non-constant incoming value is not from a cmp instruction or not
+ // produced by the last block. We could end up processing the value
+ // producing block more than once.
+ //
+ // This is an uncommon case, so we bail.
+ DEBUG(
+ dbgs()
+ << "skip: non-constant value not from cmp or not from last block.\n");
+ return false;
+ }
LastBlock = Phi.getIncomingBlock(I);
}
if (!LastBlock) {
OpenPOWER on IntegriCloud