[llvm] 16f126d - [InstCombine] Add bswap test pattern using bitreverse intrinsic
Simon Pilgrim via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 26 07:17:32 PDT 2020
Author: Simon Pilgrim
Date: 2020-10-26T14:13:18Z
New Revision: 16f126df437f9ea19383c5486181c5e2797227f2
URL: https://github.com/llvm/llvm-project/commit/16f126df437f9ea19383c5486181c5e2797227f2
DIFF: https://github.com/llvm/llvm-project/commit/16f126df437f9ea19383c5486181c5e2797227f2.diff
LOG: [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.
Added:
Modified:
llvm/test/Transforms/InstCombine/bswap.ll
Removed:
################################################################################
diff --git a/llvm/test/Transforms/InstCombine/bswap.ll b/llvm/test/Transforms/InstCombine/bswap.ll
index c0893dd23b80..ff1e329ba925 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
More information about the llvm-commits
mailing list