diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp --- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp @@ -3282,6 +3282,11 @@ return new ICmpInst(Pred, II->getArgOperand(0), ConstantInt::get(Ty, C.byteSwap())); + case Intrinsic::bitreverse: + // bitreverse(A) == C -> A == bitreverse(C) + return new ICmpInst(Pred, II->getArgOperand(0), + ConstantInt::get(Ty, C.reverseBits())); + case Intrinsic::ctlz: case Intrinsic::cttz: { // ctz(A) == bitwidth(A) -> A == 0 and likewise for != diff --git a/llvm/test/Transforms/InstCombine/cmp-intrinsic.ll b/llvm/test/Transforms/InstCombine/cmp-intrinsic.ll --- a/llvm/test/Transforms/InstCombine/cmp-intrinsic.ll +++ b/llvm/test/Transforms/InstCombine/cmp-intrinsic.ll @@ -767,8 +767,7 @@ define i1 @bitreverse_ne_22(i8 %x) { ; CHECK-LABEL: @bitreverse_ne_22( -; CHECK-NEXT: [[Y:%.*]] = call i8 @llvm.bitreverse.i8(i8 [[X:%.*]]) -; CHECK-NEXT: [[Z:%.*]] = icmp ne i8 [[Y]], 22 +; CHECK-NEXT: [[Z:%.*]] = icmp ne i8 [[X:%.*]], 104 ; CHECK-NEXT: ret i1 [[Z]] ; %y = call i8 @llvm.bitreverse.i8(i8 %x) @@ -790,8 +789,7 @@ define <2 x i1> @bitreverse_vec_eq_2_2(<2 x i8> %x) { ; CHECK-LABEL: @bitreverse_vec_eq_2_2( -; CHECK-NEXT: [[Y:%.*]] = call <2 x i8> @llvm.bitreverse.v2i8(<2 x i8> [[X:%.*]]) -; CHECK-NEXT: [[Z:%.*]] = icmp eq <2 x i8> [[Y]], +; CHECK-NEXT: [[Z:%.*]] = icmp eq <2 x i8> [[X:%.*]], ; CHECK-NEXT: ret <2 x i1> [[Z]] ; %y = call <2 x i8> @llvm.bitreverse.v2i8(<2 x i8> %x)