[llvm] r185808 - InstCombine: Fold X-C1 <u 2 -> (X & -2) == C1

David Majnemer david.majnemer at gmail.com
Mon Jul 8 05:53:24 PDT 2013


On Mon, Jul 8, 2013 at 5:44 AM, Jay Foad <jay.foad at gmail.com> wrote:

> On 8 July 2013 12:53, David Majnemer <david.majnemer at gmail.com> wrote:
>
>> InstCombine: Fold X-C1 <u 2 -> (X & -2) == C1
>>
>
> How about:
>
> * Generalizing for any power of two, e.g. X-C1 <u 16 -> (X & -16) == C1
> iff (C1 & 15) == 0
>
* Implementing the complement, C1-X <u 2 -> (X | 1) == C1 iff (C1 & 1) == 1
>

I actually already have the first one implemented. I just wanted to wait
because the general transform suffers in the following case:

x - 0xfffffff0 < 16

becomes

  %and = and i32 %x, -16
  %cmp = icmp eq i32 %and, -16

instead of

 %cmp = icmp ugt i32 %x, -17

I only wanted to handle the reverse transform for the moment. The
generalized case will be in before the middle of the week, it requires
instcombine recognizing patterns like the above and "doing the right thing
(tm)".

Thanks for the suggestion on the complement though, I'll look into that.


> Jay.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130708/f0792b45/attachment.html>


More information about the llvm-commits mailing list