[PATCH] InstCombine: Optimize (1 << X) UPred CstP2 to X UPred Log2(CstP2)

Duncan Sands duncan.sands at gmail.com
Sun Jun 9 10:37:12 PDT 2013


Hi David,

On 09/06/13 14:10, David Majnemer wrote:
> We may, after other optimizations, find ourselves with IR that looks like:
>
>    %shl = shl i32 1, %y
>    %cmp = icmp ult i32 %shl, 32
>
> However, we should transform it to:
>
>    %cmp = icmp ult i32 %y, 5
>
> The attached patch teaches visitICmpInstWithInstAndIntCst how to perform this
> transform.

while the patch looks OK, I think it could be more general.  In your example,
if the icmp ult was with, say, 30 then you still could have transformed it.
In the case of an icmp eq comparison, if the RHS is not a power of two then
it cannot be equal to the left hand side, so you could fold the comparison to
false.

Ciao, Duncan.



More information about the llvm-commits mailing list