1; RUN: opt -S -mtriple=amdgcn--amdhsa -load-store-vectorizer < %s | FileCheck %s
2; RUN: opt -S -mtriple=amdgcn--amdhsa -passes='function(load-store-vectorizer)' < %s | FileCheck %s
3
4target datalayout = "e-p:64:64-p1:64:64-p2:32:32-p3:32:32-p4:64:64-p5:32:32-p6:32:32-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-v2048:2048-n32:64-S32-A5"
5
6; Check that vectorizer can find a GEP through bitcast
7; CHECK-LABEL: @vect_zext_bitcast_f32_to_i32_idx
8; CHECK: load <4 x i32>
9define void @vect_zext_bitcast_f32_to_i32_idx(float addrspace(1)* %arg1, i32 %base) {
10  %add1 = add nuw i32 %base, 0
11  %zext1 = zext i32 %add1 to i64
12  %gep1 = getelementptr inbounds float, float addrspace(1)* %arg1, i64 %zext1
13  %f2i1 = bitcast float addrspace(1)* %gep1 to i32 addrspace(1)*
14  %load1 = load i32, i32 addrspace(1)* %f2i1, align 4
15  %add2 = add nuw i32 %base, 1
16  %zext2 = zext i32 %add2 to i64
17  %gep2 = getelementptr inbounds float, float addrspace(1)* %arg1, i64 %zext2
18  %f2i2 = bitcast float addrspace(1)* %gep2 to i32 addrspace(1)*
19  %load2 = load i32, i32 addrspace(1)* %f2i2, align 4
20  %add3 = add nuw i32 %base, 2
21  %zext3 = zext i32 %add3 to i64
22  %gep3 = getelementptr inbounds float, float addrspace(1)* %arg1, i64 %zext3
23  %f2i3 = bitcast float addrspace(1)* %gep3 to i32 addrspace(1)*
24  %load3 = load i32, i32 addrspace(1)* %f2i3, align 4
25  %add4 = add nuw i32 %base, 3
26  %zext4 = zext i32 %add4 to i64
27  %gep4 = getelementptr inbounds float, float addrspace(1)* %arg1, i64 %zext4
28  %f2i4 = bitcast float addrspace(1)* %gep4 to i32 addrspace(1)*
29  %load4 = load i32, i32 addrspace(1)* %f2i4, align 4
30  ret void
31}
32
33; CHECK-LABEL: @vect_zext_bitcast_i8_st1_to_i32_idx
34; CHECK: load i32
35; CHECK: load i32
36; CHECK: load i32
37; CHECK: load i32
38define void @vect_zext_bitcast_i8_st1_to_i32_idx(i8 addrspace(1)* %arg1, i32 %base) {
39  %add1 = add nuw i32 %base, 0
40  %zext1 = zext i32 %add1 to i64
41  %gep1 = getelementptr inbounds i8, i8 addrspace(1)* %arg1, i64 %zext1
42  %f2i1 = bitcast i8 addrspace(1)* %gep1 to i32 addrspace(1)*
43  %load1 = load i32, i32 addrspace(1)* %f2i1, align 4
44  %add2 = add nuw i32 %base, 1
45  %zext2 = zext i32 %add2 to i64
46  %gep2 = getelementptr inbounds i8,i8 addrspace(1)* %arg1, i64 %zext2
47  %f2i2 = bitcast i8 addrspace(1)* %gep2 to i32 addrspace(1)*
48  %load2 = load i32, i32 addrspace(1)* %f2i2, align 4
49  %add3 = add nuw i32 %base, 2
50  %zext3 = zext i32 %add3 to i64
51  %gep3 = getelementptr inbounds i8, i8 addrspace(1)* %arg1, i64 %zext3
52  %f2i3 = bitcast i8 addrspace(1)* %gep3 to i32 addrspace(1)*
53  %load3 = load i32, i32 addrspace(1)* %f2i3, align 4
54  %add4 = add nuw i32 %base, 3
55  %zext4 = zext i32 %add4 to i64
56  %gep4 = getelementptr inbounds i8, i8 addrspace(1)* %arg1, i64 %zext4
57  %f2i4 = bitcast i8 addrspace(1)* %gep4 to i32 addrspace(1)*
58  %load4 = load i32, i32 addrspace(1)* %f2i4, align 4
59  ret void
60}
61
62; CHECK-LABEL: @vect_zext_bitcast_i8_st4_to_i32_idx
63; CHECK: load <4 x i32>
64define void @vect_zext_bitcast_i8_st4_to_i32_idx(i8 addrspace(1)* %arg1, i32 %base) {
65  %add1 = add nuw i32 %base, 0
66  %zext1 = zext i32 %add1 to i64
67  %gep1 = getelementptr inbounds i8, i8 addrspace(1)* %arg1, i64 %zext1
68  %f2i1 = bitcast i8 addrspace(1)* %gep1 to i32 addrspace(1)*
69  %load1 = load i32, i32 addrspace(1)* %f2i1, align 4
70  %add2 = add nuw i32 %base, 4
71  %zext2 = zext i32 %add2 to i64
72  %gep2 = getelementptr inbounds i8,i8 addrspace(1)* %arg1, i64 %zext2
73  %f2i2 = bitcast i8 addrspace(1)* %gep2 to i32 addrspace(1)*
74  %load2 = load i32, i32 addrspace(1)* %f2i2, align 4
75  %add3 = add nuw i32 %base, 8
76  %zext3 = zext i32 %add3 to i64
77  %gep3 = getelementptr inbounds i8, i8 addrspace(1)* %arg1, i64 %zext3
78  %f2i3 = bitcast i8 addrspace(1)* %gep3 to i32 addrspace(1)*
79  %load3 = load i32, i32 addrspace(1)* %f2i3, align 4
80  %add4 = add nuw i32 %base, 12
81  %zext4 = zext i32 %add4 to i64
82  %gep4 = getelementptr inbounds i8, i8 addrspace(1)* %arg1, i64 %zext4
83  %f2i4 = bitcast i8 addrspace(1)* %gep4 to i32 addrspace(1)*
84  %load4 = load i32, i32 addrspace(1)* %f2i4, align 4
85  ret void
86}
87
88; CHECK-LABEL: @vect_zext_bitcast_negative_ptr_delta
89; CHECK: load <2 x i32>
90define void @vect_zext_bitcast_negative_ptr_delta(i32 addrspace(1)* %p, i32 %base) {
91  %p.bitcasted = bitcast i32 addrspace(1)* %p to i16 addrspace(1)*
92  %a.offset = add nuw i32 %base, 4
93  %t.offset.zexted = zext i32 %base to i64
94  %a.offset.zexted = zext i32 %a.offset to i64
95  %t.ptr = getelementptr inbounds i16, i16 addrspace(1)* %p.bitcasted, i64 %t.offset.zexted
96  %a.ptr = getelementptr inbounds i16, i16 addrspace(1)* %p.bitcasted, i64 %a.offset.zexted
97  %b.ptr = getelementptr inbounds i16, i16 addrspace(1)* %t.ptr, i64 6
98  %a.ptr.bitcasted = bitcast i16 addrspace(1)* %a.ptr to i32 addrspace(1)*
99  %b.ptr.bitcasted = bitcast i16 addrspace(1)* %b.ptr to i32 addrspace(1)*
100  %a.val = load i32, i32 addrspace(1)* %a.ptr.bitcasted
101  %b.val = load i32, i32 addrspace(1)* %b.ptr.bitcasted
102  ret void
103}
104
105; Check i1 corner case
106; CHECK-LABEL: @zexted_i1_gep_index
107; CHECK: load i32
108; CHECK: load i32
109define void @zexted_i1_gep_index(i32 addrspace(1)* %p, i32 %val) {
110  %selector = icmp eq i32 %val, 0
111  %flipped = xor i1 %selector, 1
112  %index.0 = zext i1 %selector to i64
113  %index.1 = zext i1 %flipped to i64
114  %gep.0 = getelementptr inbounds i32, i32 addrspace(1)* %p, i64 %index.0
115  %gep.1 = getelementptr inbounds i32, i32 addrspace(1)* %p, i64 %index.1
116  %val0 = load i32, i32 addrspace(1)* %gep.0
117  %val1 = load i32, i32 addrspace(1)* %gep.1
118  ret void
119}
120
121; Check i1 corner case
122; CHECK-LABEL: @sexted_i1_gep_index
123; CHECK: load i32
124; CHECK: load i32
125define void @sexted_i1_gep_index(i32 addrspace(1)* %p, i32 %val) {
126  %selector = icmp eq i32 %val, 0
127  %flipped = xor i1 %selector, 1
128  %index.0 = sext i1 %selector to i64
129  %index.1 = sext i1 %flipped to i64
130  %gep.0 = getelementptr inbounds i32, i32 addrspace(1)* %p, i64 %index.0
131  %gep.1 = getelementptr inbounds i32, i32 addrspace(1)* %p, i64 %index.1
132  %val0 = load i32, i32 addrspace(1)* %gep.0
133  %val1 = load i32, i32 addrspace(1)* %gep.1
134  ret void
135}
136