mirror of
https://github.com/RPCS3/llvm.git
synced 2024-12-16 00:17:32 +00:00
[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:
parent
fdd6e1b2e5
commit
7086a4139d
@ -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
|
||||
|
11
test/Transforms/InstCombine/bitreverse-fold.ll
Normal file
11
test/Transforms/InstCombine/bitreverse-fold.ll
Normal 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
|
Loading…
Reference in New Issue
Block a user