[PATCH] D19341: Add micro-optimization for 'icmp slt (or A, B), A' to instsimplify.

Nick Lewycky via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 20 14:52:14 PDT 2016


On 20 April 2016 at 14:39, David Majnemer <david.majnemer at gmail.com> wrote:

> majnemer added a subscriber: majnemer.
>
> ================
> Comment at: lib/Analysis/InstructionSimplify.cpp:2630-2639
> @@ +2629,12 @@
> +      if (Pred == ICmpInst::ICMP_SLT || Pred == ICmpInst::ICMP_SGE) {
> +        bool RHSKnownNonNegative, RHSKnownNegative;
> +        bool YKnownNonNegative, YKnownNegative;
> +        ComputeSignBit(RHS, RHSKnownNonNegative, RHSKnownNegative, Q.DL,
> 0,
> +                       Q.AC, Q.CxtI, Q.DT);
> +        ComputeSignBit(Y, YKnownNonNegative, YKnownNegative, Q.DL, 0,
> Q.AC,
> +                       Q.CxtI, Q.DT);
> +        if (RHSKnownNonNegative && YKnownNegative)
> +          return Pred == ICmpInst::ICMP_SLT ? getTrue(ITy) :
> getFalse(ITy);
> +        if (RHSKnownNegative || YKnownNonNegative)
> +          return Pred == ICmpInst::ICMP_SLT ? getFalse(ITy) :
> getTrue(ITy);
> +      }
> ----------------
> If I understand correctly, you are saying that x|y < x is true if x is
> negative and y is not negative.
> At first blush, this appears to be a specific case of a more general
> transform: x|y < x is true if x is negative and y has any bits set which
> are known not to be set in x.
>

Example x = -2, y = 1.
-2|1 < -2
-1 < -2
false.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160420/2d0ef030/attachment.html>


More information about the llvm-commits mailing list