[PATCH] InstCombineCompare with constant return false if we know it is never going to be equal

suyog sarda sardask01 at gmail.com
Fri May 30 13:24:53 PDT 2014


Hi Duncan, David

As per Duncan's suggestions i implemented, the more general way as follow :
























*if (ConstantInt *CI = dyn_cast<ConstantInt>(RHS)) {    uint32_t BitWidth =
CI->getBitWidth();    APInt LHSKnownZero(BitWidth, 0, 1);    APInt
LHSKnownOne(BitWidth, 0, 1);    computeKnownBits(LHS, LHSKnownZero,
LHSKnownOne);    APInt RHSKnownZero(BitWidth, 0, 1);    APInt
RHSKnownOne(BitWidth, 0, 1);    computeKnownBits(RHS, RHSKnownZero,
RHSKnownOne);    switch (Pred) {    // TODO: Handle for other icmp
instructions.    default:      break;    case ICmpInst::ICMP_EQ:      if
(((LHSKnownOne & RHSKnownZero) != 0) ||          ((LHSKnownZero &
RHSKnownOne) != 0))                 ---> THIS IS OUR IMPLEMENTATION
return ConstantInt::getFalse(CI->getContext());      break;    case
ICmpInst::ICMP_NE:      if (((LHSKnownOne & RHSKnownZero) != 0) ||
((LHSKnownZero & RHSKnownOne) != 0))        return
ConstantInt::getTrue(CI->getContext());      break;    }  }*

Above code passes my test case as well, i confirmed from running make
check-all with my test case added.

However, this probably fails for vectors. I am getting one regression for
following test case ;


*test/Transforms/InstCombine/align-2d-gep.ll (here we are doing some vector
store and checking some alignment).*
How can this be resolved? Even when i tried to generalize my code for more
trailing zeros rather than just comparing with one, i got the same
regression.

Your suggestions/comments are most awaited.


On Sat, May 31, 2014 at 1:23 AM, suyog sarda <sardask01 at gmail.com> wrote:

> Thanks Duncan for your valuable suggestion.
>
> I got your point, i will update the patch and add test cases for the same.
>
> Thanks a lot.
>
>
> On Fri, May 30, 2014 at 7:13 PM, Duncan Sands <duncan.sands at gmail.com>
> wrote:
>
>> Hi Suyog,
>>
>>
>> On 30/05/14 15:01, suyog wrote:
>>
>>> Gentle Ping !!
>>>
>>> http://reviews.llvm.org/D3868
>>>
>>
>> I only glanced at this but it seems much less general than it could be.
>>
>> Suppose you are analysing icmp eq A, B
>>
>> Let A_Known_Zero and A_Known_One give the bits of A that are known to be
>> zero/one.  Likewise B_Known_Zero and B_Known_One for B.
>>
>> If a bit is known to be zero for A and known to be one for B then A and B
>> cannot be equal.  Likewise, if a bit if known to be one for A and known to
>> be zero for B then A != B.
>>
>> Thus, if A_Known_Zero & B_Known_One != 0 then A != B.  Same if
>> A_Known_One & B_Known_Zero != 0.
>>
>> I think this covers your case and many more.
>>
>> Ciao, Duncan.
>>
>>
>> _______________________________________________
>> llvm-commits mailing list
>> llvm-commits at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>>
>
>
>
> --
> With regards,
> Suyog Sarda
>



-- 
With regards,
Suyog Sarda
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140531/d361314a/attachment.html>


More information about the llvm-commits mailing list