From c84f22aac5390a6a60579f56e894bab7fec94382 Mon Sep 17 00:00:00 2001 From: Suyog Sarda Date: Thu, 17 Jul 2014 06:28:15 +0000 Subject: [PATCH] Move ashr optimization from InstCombineShift to InstSimplify. Refactor code, no functionality change, test case moved from instcombine to instsimplify. Differential Revision: http://reviews.llvm.org/D4102 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@213231 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Analysis/InstructionSimplify.cpp | 5 +++++ lib/Transforms/InstCombine/InstCombineShifts.cpp | 5 ----- test/Transforms/InstCombine/ashr-nop.ll | 8 -------- test/Transforms/InstSimplify/ashr-nop.ll | 10 ++++++++++ 4 files changed, 15 insertions(+), 13 deletions(-) delete mode 100644 test/Transforms/InstCombine/ashr-nop.ll create mode 100644 test/Transforms/InstSimplify/ashr-nop.ll diff --git a/lib/Analysis/InstructionSimplify.cpp b/lib/Analysis/InstructionSimplify.cpp index fd7a4de6903..6ac1ae8d5ed 100644 --- a/lib/Analysis/InstructionSimplify.cpp +++ b/lib/Analysis/InstructionSimplify.cpp @@ -1346,6 +1346,11 @@ static Value *SimplifyAShrInst(Value *Op0, Value *Op1, bool isExact, cast(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; } diff --git a/lib/Transforms/InstCombine/InstCombineShifts.cpp b/lib/Transforms/InstCombine/InstCombineShifts.cpp index 2495747da5f..2f91c204dbd 100644 --- a/lib/Transforms/InstCombine/InstCombineShifts.cpp +++ b/lib/Transforms/InstCombine/InstCombineShifts.cpp @@ -815,10 +815,5 @@ Instruction *InstCombiner::visitAShr(BinaryOperator &I) { 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; } diff --git a/test/Transforms/InstCombine/ashr-nop.ll b/test/Transforms/InstCombine/ashr-nop.ll deleted file mode 100644 index 870ede38cd8..00000000000 --- a/test/Transforms/InstCombine/ashr-nop.ll +++ /dev/null @@ -1,8 +0,0 @@ -; RUN: opt < %s -instcombine -S | not grep ashr - -define i32 @foo(i32 %x) { - %o = and i32 %x, 1 - %n = add i32 %o, -1 - %t = ashr i32 %n, 17 - ret i32 %t -} diff --git a/test/Transforms/InstSimplify/ashr-nop.ll b/test/Transforms/InstSimplify/ashr-nop.ll new file mode 100644 index 00000000000..0914d725e40 --- /dev/null +++ b/test/Transforms/InstSimplify/ashr-nop.ll @@ -0,0 +1,10 @@ +; RUN: opt < %s -instsimplify -S | FileCheck %s + +; 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 +} -- 2.34.1