[InstCombine] Add trivial folding (bitreverse (bitreverse x)) -> x

There are plenty more instcombines we could probably do with bitreverse, but this seems like a very obvious and trivial starting point and was brought up by Hal in his review.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@252879 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
James Molloy 2015-11-12 12:39:41 +00:00
parent fdd6e1b2e5
commit 7086a4139d
2 changed files with 21 additions and 0 deletions

View File

@ -788,6 +788,16 @@ Instruction *InstCombiner::visitCallInst(CallInst &CI) {
break;
}
case Intrinsic::bitreverse: {
Value *IIOperand = II->getArgOperand(0);
Value *X = nullptr;
// bitreverse(bitreverse(x)) -> x
if (match(IIOperand, m_Intrinsic<Intrinsic::bitreverse>(m_Value(X))))
return ReplaceInstUsesWith(CI, X);
break;
}
case Intrinsic::powi:
if (ConstantInt *Power = dyn_cast<ConstantInt>(II->getArgOperand(1))) {
// powi(x, 0) -> 1.0

View File

@ -0,0 +1,11 @@
; RUN: opt < %s -instcombine -S | FileCheck %s
define i32 @test1(i32 %p) {
; CHECK-LABEL: @test1
; CHECK-NEXT: ret i32 %p
%a = call i32 @llvm.bitreverse.i32(i32 %p)
%b = call i32 @llvm.bitreverse.i32(i32 %a)
ret i32 %b
}
declare i32 @llvm.bitreverse.i32(i32) readnone