From: Simon Pilgrim Date: Mon, 26 Oct 2020 14:13:02 +0000 (+0000) Subject: [InstCombine] Add bswap test pattern using bitreverse intrinsic X-Git-Tag: llvmorg-13-init~8175 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=16f126df437f9ea19383c5486181c5e2797227f2;p=platform%2Fupstream%2Fllvm.git [InstCombine] Add bswap test pattern using bitreverse intrinsic This is mainly to help with future better bitreverse folding support but we can test it via bswap matching for now. --- diff --git a/llvm/test/Transforms/InstCombine/bswap.ll b/llvm/test/Transforms/InstCombine/bswap.ll index c0893dd..ff1e329 100644 --- a/llvm/test/Transforms/InstCombine/bswap.ll +++ b/llvm/test/Transforms/InstCombine/bswap.ll @@ -535,6 +535,28 @@ define <2 x i32> @partial_bswap_vector(<2 x i32> %x) { } declare <2 x i32> @llvm.bswap.v2i32(<2 x i32>) +define i16 @partial_bitreverse(i16 %x) { +; CHECK-LABEL: @partial_bitreverse( +; CHECK-NEXT: [[REV:%.*]] = call i16 @llvm.bitreverse.i16(i16 [[X:%.*]]) +; CHECK-NEXT: [[LO:%.*]] = and i16 [[REV]], 255 +; CHECK-NEXT: [[HI:%.*]] = and i16 [[REV]], -256 +; CHECK-NEXT: [[REVLO:%.*]] = call i16 @llvm.bitreverse.i16(i16 [[LO]]) +; CHECK-NEXT: [[REVHI:%.*]] = call i16 @llvm.bitreverse.i16(i16 [[HI]]) +; CHECK-NEXT: [[OR:%.*]] = call i16 @llvm.fshl.i16(i16 [[REVHI]], i16 [[REVLO]], i16 8) +; CHECK-NEXT: ret i16 [[OR]] +; + %rev= call i16 @llvm.bitreverse.i16(i16 %x) + %lo = and i16 %rev, 255 + %hi = and i16 %rev, -256 + %revlo = call i16 @llvm.bitreverse.i16(i16 %lo) + %revhi = call i16 @llvm.bitreverse.i16(i16 %hi) + %newlo = lshr i16 %revlo, 8 + %newhi = shl i16 %revhi, 8 + %or = or i16 %newlo, %newhi + ret i16 %or +} +declare i16 @llvm.bitreverse.i16(i16) + define i64 @bswap_and_mask_0(i64 %0) { ; CHECK-LABEL: @bswap_and_mask_0( ; CHECK-NEXT: [[TMP2:%.*]] = and i64 [[TMP0:%.*]], -72057594037927681