[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 15:48:12 PDT 2016


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

>
>
> On Wed, Apr 20, 2016 at 5:52 PM, Nick Lewycky <nlewycky at google.com> wrote:
>
>> 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.
>>
>>
> Ah, right; x|y u<= x is false if y has any bits set which are known not to
> be set in x.
>

Even for unsigned comparisons there are missed optimizations here.

Also, if x and y are both negative then x|y s< x is true if y has any bits
> set which are known not to be set in x.
>

Take x=-2 and y=-1. It has a bit (the LSB) known set in y but not x, and
they're both negative, but -2|-1 == -1, and -1 s< -2 is false.

However, both of these seem to be distinct from your transforms.
>

Right, reasoning about the transforms in this patch was hard enough.  :-)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160420/e6b125f2/attachment.html>


More information about the llvm-commits mailing list