Skip to content

Commit b85de2c

Browse files
committed
[InstCombine] Add bswap(trunc(bswap(x))) -> trunc(lshr(x, c)) vector tests
Add tests showing failure to correctly fold vector bswap(trunc(bswap(x))) intrinsic patterns
1 parent 892fdc9 commit b85de2c

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

llvm/test/Transforms/InstCombine/bswap-fold.ll

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,16 @@ define i16 @test7(i32 %A) {
3737
ret i16 %D
3838
}
3939

40+
define <2 x i16> @test7_vector(<2 x i32> %A) {
41+
; CHECK-LABEL: @test7_vector(
42+
; CHECK-NEXT: ret <2 x i16> undef
43+
;
44+
%B = tail call <2 x i32> @llvm.bswap.v2i32(<2 x i32> %A) nounwind
45+
%C = trunc <2 x i32> %B to <2 x i16>
46+
%D = tail call <2 x i16> @llvm.bswap.v2i16(<2 x i16> %C) nounwind
47+
ret <2 x i16> %D
48+
}
49+
4050
define i16 @test8(i64 %A) {
4151
; CHECK-LABEL: @test8(
4252
; CHECK-NEXT: [[TMP1:%.*]] = lshr i64 [[A:%.*]], 48
@@ -49,6 +59,16 @@ define i16 @test8(i64 %A) {
4959
ret i16 %D
5060
}
5161

62+
define <2 x i16> @test8_vector(<2 x i64> %A) {
63+
; CHECK-LABEL: @test8_vector(
64+
; CHECK-NEXT: ret <2 x i16> undef
65+
;
66+
%B = tail call <2 x i64> @llvm.bswap.v2i64(<2 x i64> %A) nounwind
67+
%C = trunc <2 x i64> %B to <2 x i16>
68+
%D = tail call <2 x i16> @llvm.bswap.v2i16(<2 x i16> %C) nounwind
69+
ret <2 x i16> %D
70+
}
71+
5272
; Misc: Fold bswap(undef) to undef.
5373
define i64 @foo() {
5474
; CHECK-LABEL: @foo(
@@ -334,4 +354,6 @@ define i64 @bs_and64i_multiuse(i64 %a, i64 %b) #0 {
334354
declare i16 @llvm.bswap.i16(i16)
335355
declare i32 @llvm.bswap.i32(i32)
336356
declare i64 @llvm.bswap.i64(i64)
357+
declare <2 x i16> @llvm.bswap.v2i16(<2 x i16>)
337358
declare <2 x i32> @llvm.bswap.v2i32(<2 x i32>)
359+
declare <2 x i64> @llvm.bswap.v2i64(<2 x i64>)

0 commit comments

Comments
 (0)