diff options
author | Jim Grosbach <grosbach@apple.com> | 2013-08-16 00:15:20 +0000 |
---|---|---|
committer | Jim Grosbach <grosbach@apple.com> | 2013-08-16 00:15:20 +0000 |
commit | 4658ce9c1f023ca8198add9eabc9ec466d23c8cb (patch) | |
tree | 26c37ce3be02aae294fa95469a2dc3edc84318a1 /lib | |
parent | da44b4f68bcf2adcb74214670a266b43a1a6888f (diff) | |
download | external_llvm-4658ce9c1f023ca8198add9eabc9ec466d23c8cb.zip external_llvm-4658ce9c1f023ca8198add9eabc9ec466d23c8cb.tar.gz external_llvm-4658ce9c1f023ca8198add9eabc9ec466d23c8cb.tar.bz2 |
InstCombine: Simplify if(x!=0 && x!=-1).
When both constants are positive or both constants are negative,
InstCombine already simplifies comparisons like this, but when
it's exactly zero and -1, the operand sorting ends up reversed
and the pattern fails to match. Handle that special case.
Follow up for rdar://14689217
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@188512 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Transforms/InstCombine/InstCombineAndOrXor.cpp | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp b/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp index b474bd8..bc8506a 100644 --- a/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp +++ b/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp @@ -849,10 +849,15 @@ Value *InstCombiner::FoldAndOfICmps(ICmpInst *LHS, ICmpInst *RHS) { case ICmpInst::ICMP_SGT: // (X != 13 & X s> 15) -> X s> 15 return RHS; case ICmpInst::ICMP_NE: + // Special case to get the ordering right when the values wrap around + // zero. + if (LHSCst->getValue() == 0 && RHSCst->getValue() == -1) + std::swap(LHSCst, RHSCst); if (LHSCst == SubOne(RHSCst)){// (X != 13 & X != 14) -> X-13 >u 1 Constant *AddCST = ConstantExpr::getNeg(LHSCst); Value *Add = Builder->CreateAdd(Val, AddCST, Val->getName()+".off"); - return Builder->CreateICmpUGT(Add, ConstantInt::get(Add->getType(), 1)); + return Builder->CreateICmpUGT(Add, ConstantInt::get(Add->getType(), 1), + Val->getName()+".cmp"); } break; // (X != 13 & X != 15) -> no change } |