diff options
author | Philip Reames <listmail@philipreames.com> | 2019-08-21 15:51:57 +0000 |
---|---|---|
committer | Philip Reames <listmail@philipreames.com> | 2019-08-21 15:51:57 +0000 |
commit | 764b0fd5a37168313cd7f8d82753b10392ff2b2b (patch) | |
tree | f41591c35127ad319972ccc800e101ae9da15479 /llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp | |
parent | f64918d092c078304f9b25c0ee6f456a39474e31 (diff) | |
download | bcm5719-llvm-764b0fd5a37168313cd7f8d82753b10392ff2b2b.tar.gz bcm5719-llvm-764b0fd5a37168313cd7f8d82753b10392ff2b2b.zip |
[instcombine] icmp eq/ne (sub C, Y), C -> icmp eq/ne Y, 0
Noticed while looking at pr43028.
llvm-svn: 369541
Diffstat (limited to 'llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp')
-rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp index 5e0a3c37979..952f295cce4 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp @@ -2411,6 +2411,11 @@ Instruction *InstCombiner::foldICmpSubConstant(ICmpInst &Cmp, const APInt *C2; APInt SubResult; + // icmp eq/ne (sub C, Y), C -> icmp eq/ne Y, 0 + if (match(X, m_APInt(C2)) && *C2 == C && Cmp.isEquality()) + return new ICmpInst(Cmp.getPredicate(), Y, + ConstantInt::get(Y->getType(), 0)); + // (icmp P (sub nuw|nsw C2, Y), C) -> (icmp swap(P) Y, C2-C) if (match(X, m_APInt(C2)) && ((Cmp.isUnsigned() && Sub->hasNoUnsignedWrap()) || |