xref: /llvm-project/llvm/test/Transforms/InstCombine/bswap-inseltpoison.ll (revision 8b56da5e9f3ba737a5ff4bf5dee654416849042f)
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2; RUN: opt < %s -passes=instcombine -S | FileCheck %s
3
4target 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"
5
6; A copy of bswap.ll, with undef at insertelement/shufflevector replaced with
7; poison
8
9define i32 @shuf_4bytes(<4 x i8> %x) {
10; CHECK-LABEL: @shuf_4bytes(
11; CHECK-NEXT:    [[TMP1:%.*]] = bitcast <4 x i8> [[X:%.*]] to i32
12; CHECK-NEXT:    [[CAST:%.*]] = call i32 @llvm.bswap.i32(i32 [[TMP1]])
13; CHECK-NEXT:    ret i32 [[CAST]]
14;
15  %bswap = shufflevector <4 x i8> %x, <4 x i8> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>
16  %cast = bitcast <4 x i8> %bswap to i32
17  ret i32 %cast
18}
19
20define i32 @shuf_load_4bytes(ptr %p) {
21; CHECK-LABEL: @shuf_load_4bytes(
22; CHECK-NEXT:    [[X1:%.*]] = load i32, ptr [[P:%.*]], align 4
23; CHECK-NEXT:    [[CAST:%.*]] = call i32 @llvm.bswap.i32(i32 [[X1]])
24; CHECK-NEXT:    ret i32 [[CAST]]
25;
26  %x = load <4 x i8>, ptr %p
27  %bswap = shufflevector <4 x i8> %x, <4 x i8> poison, <4 x i32> <i32 3, i32 2, i32 undef, i32 0>
28  %cast = bitcast <4 x i8> %bswap to i32
29  ret i32 %cast
30}
31
32define i32 @shuf_bitcast_twice_4bytes(i32 %x) {
33; CHECK-LABEL: @shuf_bitcast_twice_4bytes(
34; CHECK-NEXT:    [[CAST2:%.*]] = call i32 @llvm.bswap.i32(i32 [[X:%.*]])
35; CHECK-NEXT:    ret i32 [[CAST2]]
36;
37  %cast1 = bitcast i32 %x to <4 x i8>
38  %bswap = shufflevector <4 x i8> %cast1, <4 x i8> poison, <4 x i32> <i32 undef, i32 2, i32 1, i32 0>
39  %cast2 = bitcast <4 x i8> %bswap to i32
40  ret i32 %cast2
41}
42
43; Negative test - extra use
44declare void @use(<4 x i8>)
45
46define i32 @shuf_4bytes_extra_use(<4 x i8> %x) {
47; CHECK-LABEL: @shuf_4bytes_extra_use(
48; CHECK-NEXT:    [[BSWAP:%.*]] = shufflevector <4 x i8> [[X:%.*]], <4 x i8> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>
49; CHECK-NEXT:    call void @use(<4 x i8> [[BSWAP]])
50; CHECK-NEXT:    [[CAST:%.*]] = bitcast <4 x i8> [[BSWAP]] to i32
51; CHECK-NEXT:    ret i32 [[CAST]]
52;
53  %bswap = shufflevector <4 x i8> %x, <4 x i8> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>
54  call void @use(<4 x i8> %bswap)
55  %cast = bitcast <4 x i8> %bswap to i32
56  ret i32 %cast
57}
58
59; Negative test - scalar type is not in the data layout
60
61define i128 @shuf_16bytes(<16 x i8> %x) {
62; CHECK-LABEL: @shuf_16bytes(
63; CHECK-NEXT:    [[BSWAP:%.*]] = shufflevector <16 x i8> [[X:%.*]], <16 x i8> poison, <16 x i32> <i32 15, i32 14, i32 13, i32 12, i32 11, i32 10, i32 9, i32 8, i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>
64; CHECK-NEXT:    [[CAST:%.*]] = bitcast <16 x i8> [[BSWAP]] to i128
65; CHECK-NEXT:    ret i128 [[CAST]]
66;
67  %bswap = shufflevector <16 x i8> %x, <16 x i8> poison, <16 x i32> <i32 15, i32 14, i32 13, i32 12, i32 11, i32 10, i32 9, i32 8, i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>
68  %cast = bitcast <16 x i8> %bswap to i128
69  ret i128 %cast
70}
71
72; Negative test - don't touch widening shuffles (for now)
73
74define i32 @shuf_2bytes_widening(<2 x i8> %x) {
75; CHECK-LABEL: @shuf_2bytes_widening(
76; CHECK-NEXT:    [[BSWAP:%.*]] = shufflevector <2 x i8> [[X:%.*]], <2 x i8> poison, <4 x i32> <i32 1, i32 0, i32 poison, i32 poison>
77; CHECK-NEXT:    [[CAST:%.*]] = bitcast <4 x i8> [[BSWAP]] to i32
78; CHECK-NEXT:    ret i32 [[CAST]]
79;
80  %bswap = shufflevector <2 x i8> %x, <2 x i8> poison, <4 x i32> <i32 1, i32 0, i32 undef, i32 undef>
81  %cast = bitcast <4 x i8> %bswap to i32
82  ret i32 %cast
83}
84
85declare i32 @llvm.fshl.i32(i32, i32, i32)
86declare i32 @llvm.fshr.i32(i32, i32, i32)
87