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

David Majnemer via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 20 15:09:49 PDT 2016


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.
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.
However, both of these seem to be distinct from your transforms.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160420/65684f81/attachment-0001.html>


More information about the llvm-commits mailing list