1 ; RUN: llc -march=hexagon -O2 -mcpu=hexagonv60 -mattr=+hvxv60,hvx-length64b < %s | FileCheck %s
3 ; CHECK: vasr(v{{[0-9]+}}.h,v{{[0-9]+}}.h,r{{[0-7]+}}):sat
5 target datalayout = "e-p:32:32:32-i64:64:64-i32:32:32-i16:16:16-i1:32:32-f64:64:64-f32:32:32-v64:64:64-v32:32:32-a:0-n16:32"
6 target triple = "hexagon-unknown--elf"
8 %struct.buffer_t = type { i64, ptr, [4 x i32], [4 x i32], [4 x i32], i32, i8, i8, [6 x i8] }
10 ; Function Attrs: norecurse nounwind
11 define i32 @__test_vasr(ptr noalias nocapture %f.buffer, ptr noalias nocapture %g.buffer, ptr noalias nocapture %res.buffer) #0 {
13 %buf_host = getelementptr inbounds %struct.buffer_t, ptr %f.buffer, i32 0, i32 1
14 %f.host = load ptr, ptr %buf_host, align 4
15 %buf_dev = getelementptr inbounds %struct.buffer_t, ptr %f.buffer, i32 0, i32 0
16 %f.dev = load i64, ptr %buf_dev, align 8
17 %0 = icmp eq ptr %f.host, null
18 %1 = icmp eq i64 %f.dev, 0
19 %f.host_and_dev_are_null = and i1 %0, %1
20 %buf_min = getelementptr inbounds %struct.buffer_t, ptr %f.buffer, i32 0, i32 4, i32 0
21 %f.min.0 = load i32, ptr %buf_min, align 4
22 %buf_host10 = getelementptr inbounds %struct.buffer_t, ptr %g.buffer, i32 0, i32 1
23 %g.host = load ptr, ptr %buf_host10, align 4
24 %buf_dev11 = getelementptr inbounds %struct.buffer_t, ptr %g.buffer, i32 0, i32 0
25 %g.dev = load i64, ptr %buf_dev11, align 8
26 %2 = icmp eq ptr %g.host, null
27 %3 = icmp eq i64 %g.dev, 0
28 %g.host_and_dev_are_null = and i1 %2, %3
29 %buf_min22 = getelementptr inbounds %struct.buffer_t, ptr %g.buffer, i32 0, i32 4, i32 0
30 %g.min.0 = load i32, ptr %buf_min22, align 4
31 %buf_host27 = getelementptr inbounds %struct.buffer_t, ptr %res.buffer, i32 0, i32 1
32 %res.host = load ptr, ptr %buf_host27, align 4
33 %buf_dev28 = getelementptr inbounds %struct.buffer_t, ptr %res.buffer, i32 0, i32 0
34 %res.dev = load i64, ptr %buf_dev28, align 8
35 %4 = icmp eq ptr %res.host, null
36 %5 = icmp eq i64 %res.dev, 0
37 %res.host_and_dev_are_null = and i1 %4, %5
38 %buf_extent31 = getelementptr inbounds %struct.buffer_t, ptr %res.buffer, i32 0, i32 2, i32 0
39 %res.extent.0 = load i32, ptr %buf_extent31, align 4
40 %buf_min39 = getelementptr inbounds %struct.buffer_t, ptr %res.buffer, i32 0, i32 4, i32 0
41 %res.min.0 = load i32, ptr %buf_min39, align 4
42 %6 = add nsw i32 %res.extent.0, -1
44 %8 = add i32 %res.min.0, 63
46 %10 = add nsw i32 %res.min.0, %res.extent.0
47 %11 = add nsw i32 %10, -1
48 %12 = icmp slt i32 %9, %11
49 %13 = select i1 %12, i32 %9, i32 %11
50 %14 = add nsw i32 %10, -64
51 %15 = icmp slt i32 %res.min.0, %14
52 %16 = select i1 %15, i32 %res.min.0, i32 %14
53 %f.extent.0.required.s = sub nsw i32 %13, %16
54 br i1 %f.host_and_dev_are_null, label %true_bb, label %after_bb
56 true_bb: ; preds = %entry
57 %buf_elem_size44 = getelementptr inbounds %struct.buffer_t, ptr %f.buffer, i32 0, i32 5
58 store i32 1, ptr %buf_elem_size44, align 4
59 store i32 %16, ptr %buf_min, align 4
60 %17 = add nsw i32 %f.extent.0.required.s, 1
61 %buf_extent46 = getelementptr inbounds %struct.buffer_t, ptr %f.buffer, i32 0, i32 2, i32 0
62 store i32 %17, ptr %buf_extent46, align 4
63 %buf_stride47 = getelementptr inbounds %struct.buffer_t, ptr %f.buffer, i32 0, i32 3, i32 0
64 store i32 1, ptr %buf_stride47, align 4
65 %buf_min48 = getelementptr inbounds %struct.buffer_t, ptr %f.buffer, i32 0, i32 4, i32 1
66 store i32 0, ptr %buf_min48, align 4
67 %buf_extent49 = getelementptr inbounds %struct.buffer_t, ptr %f.buffer, i32 0, i32 2, i32 1
68 store i32 0, ptr %buf_extent49, align 4
69 %buf_stride50 = getelementptr inbounds %struct.buffer_t, ptr %f.buffer, i32 0, i32 3, i32 1
70 store i32 0, ptr %buf_stride50, align 4
71 %buf_min51 = getelementptr inbounds %struct.buffer_t, ptr %f.buffer, i32 0, i32 4, i32 2
72 store i32 0, ptr %buf_min51, align 4
73 %buf_extent52 = getelementptr inbounds %struct.buffer_t, ptr %f.buffer, i32 0, i32 2, i32 2
74 store i32 0, ptr %buf_extent52, align 4
75 %buf_stride53 = getelementptr inbounds %struct.buffer_t, ptr %f.buffer, i32 0, i32 3, i32 2
76 store i32 0, ptr %buf_stride53, align 4
77 %buf_min54 = getelementptr inbounds %struct.buffer_t, ptr %f.buffer, i32 0, i32 4, i32 3
78 store i32 0, ptr %buf_min54, align 4
79 %buf_extent55 = getelementptr inbounds %struct.buffer_t, ptr %f.buffer, i32 0, i32 2, i32 3
80 store i32 0, ptr %buf_extent55, align 4
81 %buf_stride56 = getelementptr inbounds %struct.buffer_t, ptr %f.buffer, i32 0, i32 3, i32 3
82 store i32 0, ptr %buf_stride56, align 4
85 after_bb: ; preds = %true_bb, %entry
86 br i1 %g.host_and_dev_are_null, label %true_bb57, label %after_bb59
88 true_bb57: ; preds = %after_bb
89 %buf_elem_size60 = getelementptr inbounds %struct.buffer_t, ptr %g.buffer, i32 0, i32 5
90 store i32 1, ptr %buf_elem_size60, align 4
91 store i32 %16, ptr %buf_min22, align 4
92 %18 = add nsw i32 %f.extent.0.required.s, 1
93 %buf_extent62 = getelementptr inbounds %struct.buffer_t, ptr %g.buffer, i32 0, i32 2, i32 0
94 store i32 %18, ptr %buf_extent62, align 4
95 %buf_stride63 = getelementptr inbounds %struct.buffer_t, ptr %g.buffer, i32 0, i32 3, i32 0
96 store i32 1, ptr %buf_stride63, align 4
97 %buf_min64 = getelementptr inbounds %struct.buffer_t, ptr %g.buffer, i32 0, i32 4, i32 1
98 store i32 0, ptr %buf_min64, align 4
99 %buf_extent65 = getelementptr inbounds %struct.buffer_t, ptr %g.buffer, i32 0, i32 2, i32 1
100 store i32 0, ptr %buf_extent65, align 4
101 %buf_stride66 = getelementptr inbounds %struct.buffer_t, ptr %g.buffer, i32 0, i32 3, i32 1
102 store i32 0, ptr %buf_stride66, align 4
103 %buf_min67 = getelementptr inbounds %struct.buffer_t, ptr %g.buffer, i32 0, i32 4, i32 2
104 store i32 0, ptr %buf_min67, align 4
105 %buf_extent68 = getelementptr inbounds %struct.buffer_t, ptr %g.buffer, i32 0, i32 2, i32 2
106 store i32 0, ptr %buf_extent68, align 4
107 %buf_stride69 = getelementptr inbounds %struct.buffer_t, ptr %g.buffer, i32 0, i32 3, i32 2
108 store i32 0, ptr %buf_stride69, align 4
109 %buf_min70 = getelementptr inbounds %struct.buffer_t, ptr %g.buffer, i32 0, i32 4, i32 3
110 store i32 0, ptr %buf_min70, align 4
111 %buf_extent71 = getelementptr inbounds %struct.buffer_t, ptr %g.buffer, i32 0, i32 2, i32 3
112 store i32 0, ptr %buf_extent71, align 4
113 %buf_stride72 = getelementptr inbounds %struct.buffer_t, ptr %g.buffer, i32 0, i32 3, i32 3
114 store i32 0, ptr %buf_stride72, align 4
117 after_bb59: ; preds = %true_bb57, %after_bb
118 br i1 %res.host_and_dev_are_null, label %after_bb75.thread, label %after_bb75
120 after_bb75.thread: ; preds = %after_bb59
121 %buf_elem_size76 = getelementptr inbounds %struct.buffer_t, ptr %res.buffer, i32 0, i32 5
122 store i32 1, ptr %buf_elem_size76, align 4
123 store i32 %16, ptr %buf_min39, align 4
124 %19 = add nsw i32 %f.extent.0.required.s, 1
125 store i32 %19, ptr %buf_extent31, align 4
126 %buf_stride79 = getelementptr inbounds %struct.buffer_t, ptr %res.buffer, i32 0, i32 3, i32 0
127 store i32 1, ptr %buf_stride79, align 4
128 %buf_min80 = getelementptr inbounds %struct.buffer_t, ptr %res.buffer, i32 0, i32 4, i32 1
129 store i32 0, ptr %buf_min80, align 4
130 %buf_extent81 = getelementptr inbounds %struct.buffer_t, ptr %res.buffer, i32 0, i32 2, i32 1
131 store i32 0, ptr %buf_extent81, align 4
132 %buf_stride82 = getelementptr inbounds %struct.buffer_t, ptr %res.buffer, i32 0, i32 3, i32 1
133 store i32 0, ptr %buf_stride82, align 4
134 %buf_min83 = getelementptr inbounds %struct.buffer_t, ptr %res.buffer, i32 0, i32 4, i32 2
135 store i32 0, ptr %buf_min83, align 4
136 %buf_extent84 = getelementptr inbounds %struct.buffer_t, ptr %res.buffer, i32 0, i32 2, i32 2
137 store i32 0, ptr %buf_extent84, align 4
138 %buf_stride85 = getelementptr inbounds %struct.buffer_t, ptr %res.buffer, i32 0, i32 3, i32 2
139 store i32 0, ptr %buf_stride85, align 4
140 %buf_min86 = getelementptr inbounds %struct.buffer_t, ptr %res.buffer, i32 0, i32 4, i32 3
141 store i32 0, ptr %buf_min86, align 4
142 %buf_extent87 = getelementptr inbounds %struct.buffer_t, ptr %res.buffer, i32 0, i32 2, i32 3
143 store i32 0, ptr %buf_extent87, align 4
144 %buf_stride88 = getelementptr inbounds %struct.buffer_t, ptr %res.buffer, i32 0, i32 3, i32 3
145 store i32 0, ptr %buf_stride88, align 4
146 br label %destructor_block
148 after_bb75: ; preds = %after_bb59
149 %20 = or i1 %f.host_and_dev_are_null, %g.host_and_dev_are_null
150 br i1 %20, label %destructor_block, label %"produce res"
152 "produce res": ; preds = %after_bb75
153 %21 = ashr i32 %res.extent.0, 6
154 %22 = icmp sgt i32 %21, 0
155 br i1 %22, label %"for res.s0.x.x", label %"end for res.s0.x.x", !prof !4
157 "for res.s0.x.x": ; preds = %"for res.s0.x.x", %"produce res"
158 %res.s0.x.x = phi i32 [ %41, %"for res.s0.x.x" ], [ 0, %"produce res" ]
159 %23 = shl nsw i32 %res.s0.x.x, 6
160 %24 = add nsw i32 %23, %res.min.0
161 %25 = sub nsw i32 %24, %f.min.0
162 %26 = getelementptr inbounds i8, ptr %f.host, i32 %25
163 %27 = bitcast ptr %26 to ptr
164 %28 = load <16 x i32>, ptr %27, align 1, !tbaa !5
165 %29 = tail call <32 x i32> @llvm.hexagon.V6.vzb(<16 x i32> %28)
166 %30 = sub nsw i32 %24, %g.min.0
167 %31 = getelementptr inbounds i8, ptr %g.host, i32 %30
168 %32 = bitcast ptr %31 to ptr
169 %33 = load <16 x i32>, ptr %32, align 1, !tbaa !8
170 %34 = tail call <32 x i32> @llvm.hexagon.V6.vzb(<16 x i32> %33)
171 %35 = tail call <32 x i32> @llvm.hexagon.V6.vaddh.dv(<32 x i32> %29, <32 x i32> %34)
172 %36 = tail call <16 x i32> @llvm.hexagon.V6.hi(<32 x i32> %35)
173 %37 = tail call <16 x i32> @llvm.hexagon.V6.lo(<32 x i32> %35)
174 %38 = tail call <16 x i32> @llvm.hexagon.V6.vasrhubsat(<16 x i32> %36, <16 x i32> %37, i32 4)
175 %39 = getelementptr inbounds i8, ptr %res.host, i32 %23
176 %40 = bitcast ptr %39 to ptr
177 store <16 x i32> %38, ptr %40, align 1, !tbaa !10
178 %41 = add nuw nsw i32 %res.s0.x.x, 1
179 %42 = icmp eq i32 %41, %21
180 br i1 %42, label %"end for res.s0.x.x", label %"for res.s0.x.x"
182 "end for res.s0.x.x": ; preds = %"for res.s0.x.x", %"produce res"
183 %43 = add nsw i32 %res.extent.0, 63
184 %44 = ashr i32 %43, 6
185 %45 = icmp sgt i32 %44, %21
186 br i1 %45, label %"for res.s0.x.x92.preheader", label %destructor_block, !prof !4
188 "for res.s0.x.x92.preheader": ; preds = %"end for res.s0.x.x"
189 %46 = sub i32 -64, %f.min.0
190 %47 = add i32 %46, %10
191 %48 = getelementptr inbounds i8, ptr %f.host, i32 %47
192 %49 = bitcast ptr %48 to ptr
193 %50 = load <16 x i32>, ptr %49, align 1
194 %51 = tail call <32 x i32> @llvm.hexagon.V6.vzb(<16 x i32> %50)
195 %52 = sub i32 -64, %g.min.0
196 %53 = add i32 %52, %10
197 %54 = getelementptr inbounds i8, ptr %g.host, i32 %53
198 %55 = bitcast ptr %54 to ptr
199 %56 = load <16 x i32>, ptr %55, align 1
200 %57 = tail call <32 x i32> @llvm.hexagon.V6.vzb(<16 x i32> %56)
201 %58 = tail call <32 x i32> @llvm.hexagon.V6.vaddh.dv(<32 x i32> %51, <32 x i32> %57)
202 %59 = tail call <16 x i32> @llvm.hexagon.V6.lo(<32 x i32> %58)
203 %60 = add nsw i32 %res.extent.0, -64
204 %61 = getelementptr inbounds i8, ptr %res.host, i32 %60
205 %62 = tail call <16 x i32> @llvm.hexagon.V6.hi(<32 x i32> %58)
206 %63 = tail call <16 x i32> @llvm.hexagon.V6.vasrhubsat(<16 x i32> %62, <16 x i32> %59, i32 4)
207 %64 = bitcast ptr %61 to ptr
208 store <16 x i32> %63, ptr %64, align 1, !tbaa !10
209 br label %destructor_block
211 destructor_block: ; preds = %"for res.s0.x.x92.preheader", %"end for res.s0.x.x", %after_bb75, %after_bb75.thread
215 ; Function Attrs: nounwind readnone
216 declare <32 x i32> @llvm.hexagon.V6.vaddh.dv(<32 x i32>, <32 x i32>) #1
218 ; Function Attrs: nounwind readnone
219 declare <32 x i32> @llvm.hexagon.V6.vzb(<16 x i32>) #1
221 ; Function Attrs: nounwind readnone
222 declare <16 x i32> @llvm.hexagon.V6.hi(<32 x i32>) #1
224 ; Function Attrs: nounwind readnone
225 declare <16 x i32> @llvm.hexagon.V6.lo(<32 x i32>) #1
227 ; Function Attrs: nounwind readnone
228 declare <16 x i32> @llvm.hexagon.V6.vasrhubsat(<16 x i32>, <16 x i32>, i32) #1
230 attributes #0 = { norecurse nounwind }
231 attributes #1 = { nounwind readnone }
233 !llvm.ident = !{!0, !0, !0, !0, !0, !0, !0, !0, !0, !0, !0}
234 !llvm.module.flags = !{!1, !2, !3}
236 !0 = !{!"Clang $LLVM_VERSION_MAJOR.$LLVM_VERSION_MINOR (based on LLVM 3.8.0)"}
237 !1 = !{i32 2, !"halide_use_soft_float_abi", i32 0}
238 !2 = !{i32 2, !"halide_mcpu", !"hexagonv60"}
239 !3 = !{i32 2, !"halide_mattrs", !"+hvx"}
240 !4 = !{!"branch_weights", i32 1073741824, i32 0}
241 !5 = !{!6, !6, i64 0}
243 !7 = !{!"Halide buffer"}
244 !8 = !{!9, !9, i64 0}
246 !10 = !{!11, !11, i64 0}