[llvm-commits] [llvm] r144036 - in /llvm/trunk: lib/Transforms/InstCombine/InstCombineMulDivRem.cpp test/CodeGen/X86/vec_udiv_to_shift.ll

Eli Friedman eli.friedman at gmail.com
Mon Nov 7 15:26:29 PST 2011


On Mon, Nov 7, 2011 at 3:04 PM, Pete Cooper <peter_cooper at apple.com> wrote:
> Author: pete
> Date: Mon Nov  7 17:04:49 2011
> New Revision: 144036
>
> URL: http://llvm.org/viewvc/llvm-project?rev=144036&view=rev
> Log:
> InstCombine now optimizes vector udiv by power of 2 to shifts
>
> Fixes r8429
>
> Added:
>    llvm/trunk/test/CodeGen/X86/vec_udiv_to_shift.ll
> Modified:
>    llvm/trunk/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
>
> Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp?rev=144036&r1=144035&r2=144036&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp (original)
> +++ llvm/trunk/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp Mon Nov  7 17:04:49 2011
> @@ -441,19 +441,23 @@
>   // Handle the integer div common cases
>   if (Instruction *Common = commonIDivTransforms(I))
>     return Common;
> -
> -  if (ConstantInt *C = dyn_cast<ConstantInt>(Op1)) {
> +
> +  {
>     // X udiv 2^C -> X >> C
>     // Check to see if this is an unsigned division with an exact power of 2,
>     // if so, convert to a right shift.
> -    if (C->getValue().isPowerOf2()) { // 0 not included in isPowerOf2
> +    const APInt *C;
> +    if (match(Op1, m_Power2(C))) {
>       BinaryOperator *LShr =
> -        BinaryOperator::CreateLShr(Op0,
> -            ConstantInt::get(Op0->getType(), C->getValue().logBase2()));
> +      BinaryOperator::CreateLShr(Op0,
> +                                 ConstantInt::get(Op0->getType(),
> +                                                  C->logBase2()));
>       if (I.isExact()) LShr->setIsExact();
>       return LShr;
>     }
> +  }
>
> +  if (ConstantInt *C = dyn_cast<ConstantInt>(Op1)) {
>     // X udiv C, where C >= signbit
>     if (C->getValue().isNegative()) {
>       Value *IC = Builder->CreateICmpULT(Op0, C);
>
> Added: llvm/trunk/test/CodeGen/X86/vec_udiv_to_shift.ll
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/vec_udiv_to_shift.ll?rev=144036&view=auto
> ==============================================================================
> --- llvm/trunk/test/CodeGen/X86/vec_udiv_to_shift.ll (added)
> +++ llvm/trunk/test/CodeGen/X86/vec_udiv_to_shift.ll Mon Nov  7 17:04:49 2011
> @@ -0,0 +1,15 @@
> +; RUN: opt < %s -instcombine -S | FileCheck %s
> +
> +define <8 x i16> @udiv_vec8x16(<8 x i16> %var) {
> +entry:
> +; CHECK: lshr <8 x i16> %var, <i16 5, i16 5, i16 5, i16 5, i16 5, i16 5, i16 5, i16 5>
> +%0 = udiv <8 x i16> %var, <i16 32, i16 32, i16 32, i16 32, i16 32, i16 32, i16 32, i16 32>
> +ret <8 x i16> %0
> +}
> +
> +define <4 x i32> @udiv_vec4x32(<4 x i32> %var) {
> +entry:
> +; CHECK: lshr <4 x i32> %var, <i32 4, i32 4, i32 4, i32 4>
> +%0 = udiv <4 x i32> %var, <i32 16, i32 16, i32 16, i32 16>
> +ret <4 x i32> %0
> +}
> \ No newline at end of file

^ Newline?

-Eli




More information about the llvm-commits mailing list