From: Sanjay Patel Date: Thu, 29 Aug 2019 16:48:00 +0000 (+0000) Subject: [InstCombine] add tests for bswap disguised as shuffle; NFC X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ea420823ca713048d8dfc1cf2ae68e01ba8ceb27;p=llvm [InstCombine] add tests for bswap disguised as shuffle; NFC Somewhat motivating case In PR43146: https://bugs.llvm.org/show_bug.cgi?id=43146 But that's a lot more complicated. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@370381 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/test/Transforms/InstCombine/bswap.ll b/test/Transforms/InstCombine/bswap.ll index 69be38df415..1f9e418284e 100644 --- a/test/Transforms/InstCombine/bswap.ll +++ b/test/Transforms/InstCombine/bswap.ll @@ -1,10 +1,11 @@ +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py ; RUN: opt < %s -instcombine -S | FileCheck %s target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128-n8:16:32" define i32 @test1(i32 %i) { ; CHECK-LABEL: @test1( -; CHECK-NEXT: [[TMP12:%.*]] = call i32 @llvm.bswap.i32(i32 %i) +; CHECK-NEXT: [[TMP12:%.*]] = call i32 @llvm.bswap.i32(i32 [[I:%.*]]) ; CHECK-NEXT: ret i32 [[TMP12]] ; %tmp1 = lshr i32 %i, 24 @@ -21,7 +22,7 @@ define i32 @test1(i32 %i) { define i32 @test2(i32 %arg) { ; CHECK-LABEL: @test2( -; CHECK-NEXT: [[TMP14:%.*]] = call i32 @llvm.bswap.i32(i32 %arg) +; CHECK-NEXT: [[TMP14:%.*]] = call i32 @llvm.bswap.i32(i32 [[ARG:%.*]]) ; CHECK-NEXT: ret i32 [[TMP14]] ; %tmp2 = shl i32 %arg, 24 @@ -38,7 +39,7 @@ define i32 @test2(i32 %arg) { define i16 @test3(i16 %s) { ; CHECK-LABEL: @test3( -; CHECK-NEXT: [[TMP5:%.*]] = call i16 @llvm.bswap.i16(i16 %s) +; CHECK-NEXT: [[TMP5:%.*]] = call i16 @llvm.bswap.i16(i16 [[S:%.*]]) ; CHECK-NEXT: ret i16 [[TMP5]] ; %tmp2 = lshr i16 %s, 8 @@ -49,7 +50,7 @@ define i16 @test3(i16 %s) { define i16 @test4(i16 %s) { ; CHECK-LABEL: @test4( -; CHECK-NEXT: [[TMP5:%.*]] = call i16 @llvm.bswap.i16(i16 %s) +; CHECK-NEXT: [[TMP5:%.*]] = call i16 @llvm.bswap.i16(i16 [[S:%.*]]) ; CHECK-NEXT: ret i16 [[TMP5]] ; %tmp2 = lshr i16 %s, 8 @@ -60,7 +61,7 @@ define i16 @test4(i16 %s) { define i16 @test5(i16 %a) { ; CHECK-LABEL: @test5( -; CHECK-NEXT: [[TMP_UPGRD_3:%.*]] = call i16 @llvm.bswap.i16(i16 %a) +; CHECK-NEXT: [[TMP_UPGRD_3:%.*]] = call i16 @llvm.bswap.i16(i16 [[A:%.*]]) ; CHECK-NEXT: ret i16 [[TMP_UPGRD_3]] ; %tmp = zext i16 %a to i32 @@ -80,7 +81,7 @@ define i16 @test5(i16 %a) { ; PR2842 define i32 @test6(i32 %x) nounwind readnone { ; CHECK-LABEL: @test6( -; CHECK-NEXT: [[TMP7:%.*]] = call i32 @llvm.bswap.i32(i32 %x) +; CHECK-NEXT: [[TMP7:%.*]] = call i32 @llvm.bswap.i32(i32 [[X:%.*]]) ; CHECK-NEXT: ret i32 [[TMP7]] ; %tmp = shl i32 %x, 16 @@ -102,7 +103,7 @@ declare void @extra_use(i32) define i32 @bswap32_and_first(i32 %x) { ; CHECK-LABEL: @bswap32_and_first( -; CHECK-NEXT: [[BSWAP:%.*]] = call i32 @llvm.bswap.i32(i32 %x) +; CHECK-NEXT: [[BSWAP:%.*]] = call i32 @llvm.bswap.i32(i32 [[X:%.*]]) ; CHECK-NEXT: ret i32 [[BSWAP]] ; %shl = shl i32 %x, 16 @@ -122,11 +123,11 @@ define i32 @bswap32_and_first(i32 %x) { define i32 @bswap32_and_first_extra_use(i32 %x) { ; CHECK-LABEL: @bswap32_and_first_extra_use( -; CHECK-NEXT: [[SHL:%.*]] = shl i32 %x, 16 -; CHECK-NEXT: [[SHR:%.*]] = lshr i32 %x, 16 +; CHECK-NEXT: [[SHL:%.*]] = shl i32 [[X:%.*]], 16 +; CHECK-NEXT: [[SHR:%.*]] = lshr i32 [[X]], 16 ; CHECK-NEXT: [[SWAPHALF:%.*]] = or i32 [[SHL]], [[SHR]] ; CHECK-NEXT: [[T:%.*]] = and i32 [[SWAPHALF]], 16711935 -; CHECK-NEXT: [[BSWAP:%.*]] = call i32 @llvm.bswap.i32(i32 %x) +; CHECK-NEXT: [[BSWAP:%.*]] = call i32 @llvm.bswap.i32(i32 [[X]]) ; CHECK-NEXT: call void @extra_use(i32 [[T]]) ; CHECK-NEXT: ret i32 [[BSWAP]] ; @@ -148,7 +149,7 @@ define i32 @bswap32_and_first_extra_use(i32 %x) { ; PR23863 define i32 @bswap32_shl_first(i32 %x) { ; CHECK-LABEL: @bswap32_shl_first( -; CHECK-NEXT: [[BSWAP:%.*]] = call i32 @llvm.bswap.i32(i32 %x) +; CHECK-NEXT: [[BSWAP:%.*]] = call i32 @llvm.bswap.i32(i32 [[X:%.*]]) ; CHECK-NEXT: ret i32 [[BSWAP]] ; %shl = shl i32 %x, 16 @@ -168,11 +169,11 @@ define i32 @bswap32_shl_first(i32 %x) { define i32 @bswap32_shl_first_extra_use(i32 %x) { ; CHECK-LABEL: @bswap32_shl_first_extra_use( -; CHECK-NEXT: [[SHL:%.*]] = shl i32 %x, 16 -; CHECK-NEXT: [[SHR:%.*]] = lshr i32 %x, 16 +; CHECK-NEXT: [[SHL:%.*]] = shl i32 [[X:%.*]], 16 +; CHECK-NEXT: [[SHR:%.*]] = lshr i32 [[X]], 16 ; CHECK-NEXT: [[SWAPHALF:%.*]] = or i32 [[SHL]], [[SHR]] ; CHECK-NEXT: [[T:%.*]] = shl i32 [[SWAPHALF]], 8 -; CHECK-NEXT: [[BSWAP:%.*]] = call i32 @llvm.bswap.i32(i32 %x) +; CHECK-NEXT: [[BSWAP:%.*]] = call i32 @llvm.bswap.i32(i32 [[X]]) ; CHECK-NEXT: call void @extra_use(i32 [[T]]) ; CHECK-NEXT: ret i32 [[BSWAP]] ; @@ -190,7 +191,7 @@ define i32 @bswap32_shl_first_extra_use(i32 %x) { define i16 @test8(i16 %a) { ; CHECK-LABEL: @test8( -; CHECK-NEXT: [[REV:%.*]] = call i16 @llvm.bswap.i16(i16 %a) +; CHECK-NEXT: [[REV:%.*]] = call i16 @llvm.bswap.i16(i16 [[A:%.*]]) ; CHECK-NEXT: ret i16 [[REV]] ; %conv = zext i16 %a to i32 @@ -204,7 +205,7 @@ define i16 @test8(i16 %a) { define i16 @test9(i16 %a) { ; CHECK-LABEL: @test9( -; CHECK-NEXT: [[REV:%.*]] = call i16 @llvm.bswap.i16(i16 %a) +; CHECK-NEXT: [[REV:%.*]] = call i16 @llvm.bswap.i16(i16 [[A:%.*]]) ; CHECK-NEXT: ret i16 [[REV]] ; %conv = zext i16 %a to i32 @@ -217,7 +218,7 @@ define i16 @test9(i16 %a) { define i16 @test10(i32 %a) { ; CHECK-LABEL: @test10( -; CHECK-NEXT: [[TRUNC:%.*]] = trunc i32 %a to i16 +; CHECK-NEXT: [[TRUNC:%.*]] = trunc i32 [[A:%.*]] to i16 ; CHECK-NEXT: [[REV:%.*]] = call i16 @llvm.bswap.i16(i16 [[TRUNC]]) ; CHECK-NEXT: ret i16 [[REV]] ; @@ -230,3 +231,65 @@ define i16 @test10(i32 %a) { ret i16 %conv } +define i32 @shuf_4bytes(<4 x i8> %x) { +; CHECK-LABEL: @shuf_4bytes( +; CHECK-NEXT: [[BSWAP:%.*]] = shufflevector <4 x i8> [[X:%.*]], <4 x i8> undef, <4 x i32> +; CHECK-NEXT: [[CAST:%.*]] = bitcast <4 x i8> [[BSWAP]] to i32 +; CHECK-NEXT: ret i32 [[CAST]] +; + %bswap = shufflevector <4 x i8> %x, <4 x i8> undef, <4 x i32> + %cast = bitcast <4 x i8> %bswap to i32 + ret i32 %cast +} + +define i32 @shuf_load_4bytes(<4 x i8>* %p) { +; CHECK-LABEL: @shuf_load_4bytes( +; CHECK-NEXT: [[X:%.*]] = load <4 x i8>, <4 x i8>* [[P:%.*]], align 4 +; CHECK-NEXT: [[BSWAP:%.*]] = shufflevector <4 x i8> [[X]], <4 x i8> undef, <4 x i32> +; CHECK-NEXT: [[CAST:%.*]] = bitcast <4 x i8> [[BSWAP]] to i32 +; CHECK-NEXT: ret i32 [[CAST]] +; + %x = load <4 x i8>, <4 x i8>* %p + %bswap = shufflevector <4 x i8> %x, <4 x i8> undef, <4 x i32> + %cast = bitcast <4 x i8> %bswap to i32 + ret i32 %cast +} + +define i32 @shuf_bitcast_twice_4bytes(i32 %x) { +; CHECK-LABEL: @shuf_bitcast_twice_4bytes( +; CHECK-NEXT: [[CAST1:%.*]] = bitcast i32 [[X:%.*]] to <4 x i8> +; CHECK-NEXT: [[BSWAP:%.*]] = shufflevector <4 x i8> [[CAST1]], <4 x i8> undef, <4 x i32> +; CHECK-NEXT: [[CAST2:%.*]] = bitcast <4 x i8> [[BSWAP]] to i32 +; CHECK-NEXT: ret i32 [[CAST2]] +; + %cast1 = bitcast i32 %x to <4 x i8> + %bswap = shufflevector <4 x i8> %cast1, <4 x i8> undef, <4 x i32> + %cast2 = bitcast <4 x i8> %bswap to i32 + ret i32 %cast2 +} + +declare void @use(<4 x i8>) + +define i32 @shuf_4bytes_extra_use(<4 x i8> %x) { +; CHECK-LABEL: @shuf_4bytes_extra_use( +; CHECK-NEXT: [[BSWAP:%.*]] = shufflevector <4 x i8> [[X:%.*]], <4 x i8> undef, <4 x i32> +; CHECK-NEXT: call void @use(<4 x i8> [[BSWAP]]) +; CHECK-NEXT: [[CAST:%.*]] = bitcast <4 x i8> [[BSWAP]] to i32 +; CHECK-NEXT: ret i32 [[CAST]] +; + %bswap = shufflevector <4 x i8> %x, <4 x i8> undef, <4 x i32> + call void @use(<4 x i8> %bswap) + %cast = bitcast <4 x i8> %bswap to i32 + ret i32 %cast +} + +define i128 @shuf_load_16bytes(<16 x i8> %x) { +; CHECK-LABEL: @shuf_load_16bytes( +; CHECK-NEXT: [[BSWAP:%.*]] = shufflevector <16 x i8> [[X:%.*]], <16 x i8> undef, <16 x i32> +; CHECK-NEXT: [[CAST:%.*]] = bitcast <16 x i8> [[BSWAP]] to i128 +; CHECK-NEXT: ret i128 [[CAST]] +; + %bswap = shufflevector <16 x i8> %x, <16 x i8> undef, <16 x i32> + %cast = bitcast <16 x i8> %bswap to i128 + ret i128 %cast +}