[llvm-commits] [PATCH] Simplify negated bit test

Jakub Staszak kubastaszak at gmail.com
Sun Dec 9 06:57:09 PST 2012


Hi David,

In general your patch looks fine for me, but I see some areas for the improvement:
1. Your patch works only one way:
(1 << x)&~y != 0  into (1 << x)&y == 0, however
(1 << x)&~y == 0  into (1 << x)&y != 0 is not supported. 

2. It doesn't have to be 1 which is shifted. It works with any power-of-two value (you can use m_Power2 pattern).

- Kuba

On Dec 9, 2012, at 12:53 AM, David Majnemer <david.majnemer at gmail.com> wrote:

> The attached patched takes a sequence like:
>  %neg = xor i32 %A, -1
>  %shl = shl i32 1, %B
>  %and = and i32 %shl, %neg
>  %cmp = icmp ne i32 %and, 0
> 
> and turns it into:
>  %shl = shl i32 1, %B
>  %and = and i32 %shl, %A
>  %cmp = icmp eq i32 %and, 0
> 
> The patch includes a test case that exercises this transform.
> 
> Examples of frontend code that could generate sequence 1 is:
> 
> bool fun1(unsigned A, unsigned B) { return ~A & (1 << B); }
> 
> An example of sequence 2 is:
> bool fun2(unsigned A, unsigned B) { return !(A & (1 << B)); }
> 
> With this patch, they would have the same IR.
> <bit_test.patch>_______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits





More information about the llvm-commits mailing list