[llvm-commits] [PATCH, instcombine] X ^ Y -> X or Y

Sean Silva silvas at purdue.edu
Tue Dec 4 16:25:58 PST 2012


+; unsigned foo(unsigned x) { nsigned t = x ^ 1234; ;  return (t >> 16) + t;}

typo 'nsigned'

-- Sean Silva

On Tue, Dec 4, 2012 at 5:07 PM, Shuxin Yang <shuxin.llvm at gmail.com> wrote:
> Hi,
>
>   For rdar://12329730, last piece.
>
>   This change attempts to simplify (X^Y) -> X or Y in the user's context if
> we know that
>  only bits from X or Y are demanded.
>
>    A minimized case is provided bellow. This change will simplify "t>>9"
> into "var1 >>9".
>
> ==============================
> unsigned foo (unsigned val1, unsigned val2) {
>     unsigned t = val1 ^ 1234;
>     return (t >> 16) | t; // NOTE: t is used more than once.
> }
> ===============================
>
>   Note that if the "t" were used only once, the expression would be finally
> optimized as well.
> However, with with this change, the optimization will take place earlier.
>
>   The change to test39 at shift.ll is not obvious.  We can verify the
> correctness by
> starting tmp4 with value {b7, b6, ... b0} (NOTE: tmp4 is of type i8).
>
> Thank you for review
> Shuxin
>
>  test39 WAS:
> ========
> define i8 @test39(i32 %a0) {
> entry:
>   %tmp4 = trunc i32 %a0 to i8
>   %tmp5 = shl i8 %tmp4, 5
>   %tmp49 = shl i8 %tmp4, 6
>   %tmp50 = and i8 %tmp49, 64
>   %tmp51 = xor i8 %tmp50, %tmp5
>   %tmp53 = lshr i8 %tmp51, 7
>   %tmp54 = shl nuw nsw i8 %tmp53, 4
>   %tmp551 = or i8 %tmp54, %tmp51
>   ret i8 %tmp551
> }
>
>  IS:
> ===
> define i8 @test39(i32 %a0) {
> entry:
>   %tmp4 = trunc i32 %a0 to i8
>   %tmp5 = shl i8 %tmp4, 5
>   %tmp49 = shl i8 %tmp4, 6
>   %tmp50 = and i8 %tmp49, 64
>   %tmp51 = xor i8 %tmp50, %tmp5
>   %0 = shl i8 %tmp4, 2  ; **** diff **
>   %tmp54 = and i8 %0, 16 ; **** diff **
>   %tmp551 = or i8 %tmp54, %tmp51
>   ret i8 %tmp551
> }
>
>
>
> _______________________________________________
> 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