[llvm] r174152 - Optimize shift lefts of a constant by a value plus constant into a single shift.
Nuno Lopes
nunoplopes at sapo.pt
Fri Feb 1 01:54:33 PST 2013
Hi Nadav,
I don't think this transformation is correct when the 'add' overflows.
E.g. (2 bits):
01 << (01 + 11) == 01 << 00 == 01
(01 << 11) << 01 == 00 << 01 == 00
Nuno
Quoting Nadav Rotem <nrotem at apple.com>:
> Author: nadav
> Date: Fri Feb 1 00:45:40 2013
> New Revision: 174152
>
> URL: http://llvm.org/viewvc/llvm-project?rev=174152&view=rev
> Log:
> Optimize shift lefts of a constant by a value plus constant into a
> single shift.
>
>
> Modified:
> llvm/trunk/lib/Transforms/InstCombine/InstCombineShifts.cpp
> llvm/trunk/test/Transforms/InstCombine/shift.ll
>
> Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineShifts.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineShifts.cpp?rev=174152&r1=174151&r2=174152&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Transforms/InstCombine/InstCombineShifts.cpp (original)
> +++ llvm/trunk/lib/Transforms/InstCombine/InstCombineShifts.cpp Fri
> Feb 1 00:45:40 2013
> @@ -709,6 +709,12 @@ Instruction *InstCombiner::visitShl(Bina
> match(I.getOperand(1), m_Constant(C2)))
> return BinaryOperator::CreateShl(ConstantExpr::getShl(C1, C2), A);
>
> + // shl (c1 , add(y , c2)) -> (shl (shl(c1, c2)), y)
> + if (match(I.getOperand(0), m_Constant(C1)) &&
> + match(I.getOperand(1), m_Add(m_Value(A), m_Constant(C2)))) {
> + return BinaryOperator::CreateShl(ConstantExpr::getShl(C1, C2), A);
> + }
> +
> return 0;
> }
>
>
> Modified: llvm/trunk/test/Transforms/InstCombine/shift.ll
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/shift.ll?rev=174152&r1=174151&r2=174152&view=diff
> ==============================================================================
> --- llvm/trunk/test/Transforms/InstCombine/shift.ll (original)
> +++ llvm/trunk/test/Transforms/InstCombine/shift.ll Fri Feb 1 00:45:40 2013
> @@ -745,3 +745,23 @@ define i32 @test62(i32 %x) {
> ; CHECK: @test62
> ; CHECK: ashr exact i32 %x, 3
> }
> +
> +; CHECK: @test63
> +; CHECK: shl <4 x i32> <i32 1, i32 2, i32 4, i32 8>, %B
> +define <4 x i32> @test63(i32 %n) {
> +entry:
> + %K = insertelement <4 x i32> undef, i32 %n, i32 0
> + %B = shufflevector <4 x i32> %K, <4 x i32> undef, <4 x i32>
> zeroinitializer
> + %A = add <4 x i32> %B, <i32 0, i32 1, i32 2, i32 3>
> + %T = shl <4 x i32> <i32 1, i32 1, i32 1, i32 1>, %A
> + ret <4 x i32> %T
> +}
> +
> +; CHECK: @test64
> +; CHECK: shl i32 524288, %n
> +define i32 @test64(i32 %n) {
> +entry:
> + %A = add i32 %n, 19
> + %T = shl i32 1 , %A
> + ret i32 %T
> +}
>
>
> _______________________________________________
> 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