[llvm] r188512 - InstCombine: Simplify if(x!=0 && x!=-1).

Jim Grosbach grosbach at apple.com
Fri Aug 16 10:05:56 PDT 2013


On Aug 15, 2013, at 8:15 PM, Eli Friedman <eli.friedman at gmail.com> wrote:

> On Thu, Aug 15, 2013 at 5:15 PM, Jim Grosbach <grosbach at apple.com> wrote:
> Author: grosbach
> Date: Thu Aug 15 19:15:20 2013
> New Revision: 188512
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=188512&view=rev
> Log:
> 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
> 
> Modified:
>     llvm/trunk/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
>     llvm/trunk/test/Transforms/InstCombine/and2.ll
> 
> Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp?rev=188512&r1=188511&r2=188512&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp (original)
> +++ llvm/trunk/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp Thu Aug 15 19:15:20 2013
> @@ -849,10 +849,15 @@ Value *InstCombiner::FoldAndOfICmps(ICmp
>      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);
> 
> 
> This is using the operator== which takes uint64_t, which is probably not what you want for the "-1" check.  Try isAllOnesValue() instead.
> 

Absolutely right, of course. Thanks!

r188563

-Jim

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130816/36db1552/attachment.html>


More information about the llvm-commits mailing list