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
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
--- /dev/null
+; 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