summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
authorClement Courbet <courbet@google.com>2018-03-13 07:05:55 +0000
committerClement Courbet <courbet@google.com>2018-03-13 07:05:55 +0000
commit9f0b3170bcea739ce54af7cc2819cc3287c123d0 (patch)
treeac7b00a04b1a60066d1b05ef588cb94a3e1c6989 /llvm/lib
parent82bf8bcb4facac36b18208f96b9f99c6f1af9f19 (diff)
downloadbcm5719-llvm-9f0b3170bcea739ce54af7cc2819cc3287c123d0.tar.gz
bcm5719-llvm-9f0b3170bcea739ce54af7cc2819cc3287c123d0.zip
[MergeICmps] Make sure that the comparison only has one use.
Summary: Fixes PR36557. Reviewers: trentxintong, spatel Subscribers: mstorsjo, llvm-commits Differential Revision: https://reviews.llvm.org/D44083 llvm-svn: 327372
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/Transforms/Scalar/MergeICmps.cpp9
1 files changed, 9 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/Scalar/MergeICmps.cpp b/llvm/lib/Transforms/Scalar/MergeICmps.cpp
index 4e54f1e47e7..5b82c320e7c 100644
--- a/llvm/lib/Transforms/Scalar/MergeICmps.cpp
+++ b/llvm/lib/Transforms/Scalar/MergeICmps.cpp
@@ -177,6 +177,15 @@ bool BCECmpBlock::doesOtherWork() const {
// BCE atoms, returns the comparison.
BCECmpBlock visitICmp(const ICmpInst *const CmpI,
const ICmpInst::Predicate ExpectedPredicate) {
+ // The comparison can only be used once:
+ // - For intermediate blocks, as a branch condition.
+ // - For the final block, as an incoming value for the Phi.
+ // If there are any other uses of the comparison, we cannot merge it with
+ // other comparisons as we would create an orphan use of the value.
+ if (!CmpI->hasOneUse()) {
+ DEBUG(dbgs() << "cmp has several uses\n");
+ return {};
+ }
if (CmpI->getPredicate() == ExpectedPredicate) {
DEBUG(dbgs() << "cmp "
<< (ExpectedPredicate == ICmpInst::ICMP_EQ ? "eq" : "ne")
OpenPOWER on IntegriCloud