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

Eli Friedman eli.friedman at gmail.com
Thu Aug 15 20:15:45 PDT 2013


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.

-Eli
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130815/cf716721/attachment.html>


More information about the llvm-commits mailing list