aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/CodeGen/CodeGenPrepare.cpp
diff options
context:
space:
mode:
authorSanjay Patel <spatel@rotateright.com>2019-03-04 22:47:13 +0000
committerSanjay Patel <spatel@rotateright.com>2019-03-04 22:47:13 +0000
commit3b2d0bc7c274c76198933c8c7d799b61a70dec82 (patch)
tree252fe24f0f8271dedfb7b425dd3c41baa1266d1f /llvm/lib/CodeGen/CodeGenPrepare.cpp
parentcaf62b1d47e8a9aeb43787a18d6e5c1d5c1f8b70 (diff)
downloadllvm-3b2d0bc7c274c76198933c8c7d799b61a70dec82.zip
llvm-3b2d0bc7c274c76198933c8c7d799b61a70dec82.tar.gz
llvm-3b2d0bc7c274c76198933c8c7d799b61a70dec82.tar.bz2
[CodeGenPrepare] avoid crashing on non-canonical/degenerate code
The test is reduced from an example in the post-commit thread for: rL354746 http://lists.llvm.org/pipermail/llvm-commits/Week-of-Mon-20190304/632396.html While we must avoid dying here, the real question should be: Why is non-canonical and/or degenerate code making it to CGP when using the new pass manager? llvm-svn: 355345
Diffstat (limited to 'llvm/lib/CodeGen/CodeGenPrepare.cpp')
-rw-r--r--llvm/lib/CodeGen/CodeGenPrepare.cpp5
1 files changed, 5 insertions, 0 deletions
diff --git a/llvm/lib/CodeGen/CodeGenPrepare.cpp b/llvm/lib/CodeGen/CodeGenPrepare.cpp
index e56bd03..3996bdf 100644
--- a/llvm/lib/CodeGen/CodeGenPrepare.cpp
+++ b/llvm/lib/CodeGen/CodeGenPrepare.cpp
@@ -1203,6 +1203,11 @@ static bool matchUAddWithOverflowConstantEdgeCases(CmpInst *Cmp,
// Add = add A, 1; Cmp = icmp eq A,-1 (overflow if A is max val)
// Add = add A,-1; Cmp = icmp ne A, 0 (overflow if A is non-zero)
Value *A = Cmp->getOperand(0), *B = Cmp->getOperand(1);
+
+ // We are not expecting non-canonical/degenerate code. Just bail out.
+ if (isa<Constant>(A))
+ return false;
+
ICmpInst::Predicate Pred = Cmp->getPredicate();
if (Pred == ICmpInst::ICMP_EQ && match(B, m_AllOnes()))
B = ConstantInt::get(B->getType(), 1);