From: Simon Pilgrim Date: Wed, 30 Sep 2020 14:42:53 +0000 (+0100) Subject: [InstCombine] Add bswap(trunc(bswap(x))) -> trunc(lshr(x, c)) vector tests X-Git-Tag: llvmorg-13-init~10502 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b85de2c69cf3d6fbc2ad3439a6224667a58f704c;p=platform%2Fupstream%2Fllvm.git [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 --- diff --git a/llvm/test/Transforms/InstCombine/bswap-fold.ll b/llvm/test/Transforms/InstCombine/bswap-fold.ll index 5e9c092..c90b880 100644 --- a/llvm/test/Transforms/InstCombine/bswap-fold.ll +++ b/llvm/test/Transforms/InstCombine/bswap-fold.ll @@ -37,6 +37,16 @@ define i16 @test7(i32 %A) { ret i16 %D } +define <2 x i16> @test7_vector(<2 x i32> %A) { +; CHECK-LABEL: @test7_vector( +; CHECK-NEXT: ret <2 x i16> undef +; + %B = tail call <2 x i32> @llvm.bswap.v2i32(<2 x i32> %A) nounwind + %C = trunc <2 x i32> %B to <2 x i16> + %D = tail call <2 x i16> @llvm.bswap.v2i16(<2 x i16> %C) nounwind + ret <2 x i16> %D +} + define i16 @test8(i64 %A) { ; CHECK-LABEL: @test8( ; CHECK-NEXT: [[TMP1:%.*]] = lshr i64 [[A:%.*]], 48 @@ -49,6 +59,16 @@ define i16 @test8(i64 %A) { ret i16 %D } +define <2 x i16> @test8_vector(<2 x i64> %A) { +; CHECK-LABEL: @test8_vector( +; CHECK-NEXT: ret <2 x i16> undef +; + %B = tail call <2 x i64> @llvm.bswap.v2i64(<2 x i64> %A) nounwind + %C = trunc <2 x i64> %B to <2 x i16> + %D = tail call <2 x i16> @llvm.bswap.v2i16(<2 x i16> %C) nounwind + ret <2 x i16> %D +} + ; Misc: Fold bswap(undef) to undef. define i64 @foo() { ; CHECK-LABEL: @foo( @@ -334,4 +354,6 @@ define i64 @bs_and64i_multiuse(i64 %a, i64 %b) #0 { declare i16 @llvm.bswap.i16(i16) declare i32 @llvm.bswap.i32(i32) declare i64 @llvm.bswap.i64(i64) +declare <2 x i16> @llvm.bswap.v2i16(<2 x i16>) declare <2 x i32> @llvm.bswap.v2i32(<2 x i32>) +declare <2 x i64> @llvm.bswap.v2i64(<2 x i64>)