Skip to content

Commit

Permalink
Move ashr optimization from InstCombineShift to InstSimplify.
Browse files Browse the repository at this point in the history
Refactor code, no functionality change, test case moved from instcombine to instsimplify.

Differential Revision: http://reviews.llvm.org/D4102
 

llvm-svn: 213231
  • Loading branch information
Suyog Sarda committed Jul 17, 2014
1 parent ac6e39c commit 6886241
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 13 deletions.
5 changes: 5 additions & 0 deletions llvm/lib/Analysis/InstructionSimplify.cpp
Expand Up @@ -1346,6 +1346,11 @@ static Value *SimplifyAShrInst(Value *Op0, Value *Op1, bool isExact,
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;
}

Expand Down
5 changes: 0 additions & 5 deletions llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp
Expand Up @@ -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;
}
8 changes: 0 additions & 8 deletions llvm/test/Transforms/InstCombine/ashr-nop.ll

This file was deleted.

10 changes: 10 additions & 0 deletions llvm/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
}

0 comments on commit 6886241

Please sign in to comment.