[PATCH] [InstCombine/InstSimplify] Move ashr optimization from Instcombine to Instsimplify

Nick Lewycky nlewycky at google.com
Fri Jun 27 10:51:07 PDT 2014


On 27 June 2014 05:31, suyog <suyog.sarda at samsung.com> wrote:

> Hi Nick,
>
> I modified the test case to use FileCheck.
>
> I also believe the test case is in accordance to what we taught
> instsimplify as mentioned by Rahul above.
> Also, this test case was the original one for instcombine, the code for
> which we moved to instsimplify.
>
> Can you point out what's specific wrong in the test case? Your inputs are
> most welcomed :)
>
> http://reviews.llvm.org/D4102
>
> Files:
>   lib/Analysis/InstructionSimplify.cpp
>   lib/Transforms/InstCombine/InstCombineShifts.cpp
>   test/Transforms/InstSimplify/ashr-nop.ll
>
> Index: lib/Analysis/InstructionSimplify.cpp
> ===================================================================
> --- lib/Analysis/InstructionSimplify.cpp
> +++ lib/Analysis/InstructionSimplify.cpp
> @@ -1346,6 +1346,11 @@
>        cast<OverflowingBinaryOperator>(Op0)->hasNoSignedWrap())
>      return X;
>
> +  // Arithmetic shifting an all-sign-bit value is a no-op.
> +  unsigned NumSignBits = ComputeNumSignBits(Op0);
> +  if (NumSignBits == Op0->getType()->getScalarSizeInBits())
> +    return Op0;
> +
>    return nullptr;
>  }
>
> Index: lib/Transforms/InstCombine/InstCombineShifts.cpp
> ===================================================================
> --- lib/Transforms/InstCombine/InstCombineShifts.cpp
> +++ lib/Transforms/InstCombine/InstCombineShifts.cpp
> @@ -815,10 +815,5 @@
>
>  APInt::getSignBit(I.getType()->getScalarSizeInBits())))
>      return BinaryOperator::CreateLShr(Op0, Op1);
>
> -  // Arithmetic shifting an all-sign-bit value is a no-op.
> -  unsigned NumSignBits = ComputeNumSignBits(Op0);
> -  if (NumSignBits == Op0->getType()->getScalarSizeInBits())
> -    return ReplaceInstUsesWith(I, Op0);
> -
>    return nullptr;
>  }
> Index: test/Transforms/InstSimplify/ashr-nop.ll
> ===================================================================
> --- test/Transforms/InstSimplify/ashr-nop.ll
> +++ test/Transforms/InstSimplify/ashr-nop.ll
> @@ -0,0 +1,10 @@
> +; RUN: opt < %s -instcombine -S | FileCheck %s
>

Did you mean -instsimplify?


> +
> +; CHECK-LABEL: @foo
> +; CHECK-NOT: ashr
> +define i32 @foo(i32 %x) {
> +  %o = and i32 %x, 1
> +  %n = add i32 %o, -1
> +  %t = ashr i32 %n, 17
> +  ret i32 %t
> +}
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140627/7578919b/attachment.html>


More information about the llvm-commits mailing list