xref: /llvm-project/llvm/test/CodeGen/AMDGPU/amdgpu-simplify-libcall-sqrt.ll (revision daecc303bb719ed63566fcb343afec169826f82c)
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 2
2; RUN: opt -S -mtriple=amdgcn-amd-amdhsa -passes=amdgpu-simplifylib %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-p7:160:256:256:32-p8:128:128-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-G1-ni:7:8:9"
5
6declare float @_Z4sqrtf(float)
7declare <2 x float> @_Z4sqrtDv2_f(<2 x float>)
8declare <3 x float> @_Z4sqrtDv3_f(<3 x float>)
9declare <4 x float> @_Z4sqrtDv4_f(<4 x float>)
10declare <8 x float> @_Z4sqrtDv8_f(<8 x float>)
11declare <16 x float> @_Z4sqrtDv16_f(<16 x float>)
12
13declare double @_Z4sqrtd(double)
14declare <2 x double> @_Z4sqrtDv2_d(<2 x double>)
15declare <3 x double> @_Z4sqrtDv3_d(<3 x double>)
16declare <4 x double> @_Z4sqrtDv4_d(<4 x double>)
17declare <8 x double> @_Z4sqrtDv8_d(<8 x double>)
18declare <16 x double> @_Z4sqrtDv16_d(<16 x double>)
19
20declare half @_Z4sqrtDh(half)
21declare <2 x half> @_Z4sqrtDv2_Dh(<2 x half>)
22declare <3 x half> @_Z4sqrtDv3_Dh(<3 x half>)
23declare <4 x half> @_Z4sqrtDv4_Dh(<4 x half>)
24declare <8 x half> @_Z4sqrtDv8_Dh(<8 x half>)
25declare <16 x half> @_Z4sqrtDv16_Dh(<16 x half>)
26
27define float @test_sqrt_f32(float %arg) {
28; CHECK-LABEL: define float @test_sqrt_f32
29; CHECK-SAME: (float [[ARG:%.*]]) {
30; CHECK-NEXT:    [[SQRT:%.*]] = tail call float @llvm.sqrt.f32(float [[ARG]]), !fpmath [[META0:![0-9]+]]
31; CHECK-NEXT:    ret float [[SQRT]]
32;
33  %sqrt = tail call float @_Z4sqrtf(float %arg), !fpmath !0
34  ret float %sqrt
35}
36
37define <2 x float> @test_sqrt_v2f32(<2 x float> %arg) {
38; CHECK-LABEL: define <2 x float> @test_sqrt_v2f32
39; CHECK-SAME: (<2 x float> [[ARG:%.*]]) {
40; CHECK-NEXT:    [[SQRT:%.*]] = tail call <2 x float> @llvm.sqrt.v2f32(<2 x float> [[ARG]]), !fpmath [[META0]]
41; CHECK-NEXT:    ret <2 x float> [[SQRT]]
42;
43  %sqrt = tail call <2 x float> @_Z4sqrtDv2_f(<2 x float> %arg), !fpmath !0
44  ret <2 x float> %sqrt
45}
46
47define <3 x float> @test_sqrt_v3f32(<3 x float> %arg) {
48; CHECK-LABEL: define <3 x float> @test_sqrt_v3f32
49; CHECK-SAME: (<3 x float> [[ARG:%.*]]) {
50; CHECK-NEXT:    [[SQRT:%.*]] = tail call <3 x float> @llvm.sqrt.v3f32(<3 x float> [[ARG]]), !fpmath [[META0]]
51; CHECK-NEXT:    ret <3 x float> [[SQRT]]
52;
53  %sqrt = tail call <3 x float> @_Z4sqrtDv3_f(<3 x float> %arg), !fpmath !0
54  ret <3 x float> %sqrt
55}
56
57define <4 x float> @test_sqrt_v4f32(<4 x float> %arg) {
58; CHECK-LABEL: define <4 x float> @test_sqrt_v4f32
59; CHECK-SAME: (<4 x float> [[ARG:%.*]]) {
60; CHECK-NEXT:    [[SQRT:%.*]] = tail call <4 x float> @llvm.sqrt.v4f32(<4 x float> [[ARG]]), !fpmath [[META0]]
61; CHECK-NEXT:    ret <4 x float> [[SQRT]]
62;
63  %sqrt = tail call <4 x float> @_Z4sqrtDv4_f(<4 x float> %arg), !fpmath !0
64  ret <4 x float> %sqrt
65}
66
67define <8 x float> @test_sqrt_v8f32(<8 x float> %arg) {
68; CHECK-LABEL: define <8 x float> @test_sqrt_v8f32
69; CHECK-SAME: (<8 x float> [[ARG:%.*]]) {
70; CHECK-NEXT:    [[SQRT:%.*]] = tail call <8 x float> @llvm.sqrt.v8f32(<8 x float> [[ARG]]), !fpmath [[META0]]
71; CHECK-NEXT:    ret <8 x float> [[SQRT]]
72;
73  %sqrt = tail call <8 x float> @_Z4sqrtDv8_f(<8 x float> %arg), !fpmath !0
74  ret <8 x float> %sqrt
75}
76
77define <16 x float> @test_sqrt_v16f32(<16 x float> %arg) {
78; CHECK-LABEL: define <16 x float> @test_sqrt_v16f32
79; CHECK-SAME: (<16 x float> [[ARG:%.*]]) {
80; CHECK-NEXT:    [[SQRT:%.*]] = tail call <16 x float> @llvm.sqrt.v16f32(<16 x float> [[ARG]]), !fpmath [[META0]]
81; CHECK-NEXT:    ret <16 x float> [[SQRT]]
82;
83  %sqrt = tail call <16 x float> @_Z4sqrtDv16_f(<16 x float> %arg), !fpmath !0
84  ret <16 x float> %sqrt
85}
86
87define float @test_sqrt_cr_f32(float %arg) {
88; CHECK-LABEL: define float @test_sqrt_cr_f32
89; CHECK-SAME: (float [[ARG:%.*]]) {
90; CHECK-NEXT:    [[SQRT:%.*]] = tail call float @llvm.sqrt.f32(float [[ARG]])
91; CHECK-NEXT:    ret float [[SQRT]]
92;
93  %sqrt = tail call float @_Z4sqrtf(float %arg)
94  ret float %sqrt
95}
96
97define <2 x float> @test_sqrt_cr_v2f32(<2 x float> %arg) {
98; CHECK-LABEL: define <2 x float> @test_sqrt_cr_v2f32
99; CHECK-SAME: (<2 x float> [[ARG:%.*]]) {
100; CHECK-NEXT:    [[SQRT:%.*]] = tail call <2 x float> @llvm.sqrt.v2f32(<2 x float> [[ARG]])
101; CHECK-NEXT:    ret <2 x float> [[SQRT]]
102;
103  %sqrt = tail call <2 x float> @_Z4sqrtDv2_f(<2 x float> %arg)
104  ret <2 x float> %sqrt
105}
106
107define <3 x float> @test_sqrt_cr_v3f32(<3 x float> %arg) {
108; CHECK-LABEL: define <3 x float> @test_sqrt_cr_v3f32
109; CHECK-SAME: (<3 x float> [[ARG:%.*]]) {
110; CHECK-NEXT:    [[SQRT:%.*]] = tail call <3 x float> @llvm.sqrt.v3f32(<3 x float> [[ARG]])
111; CHECK-NEXT:    ret <3 x float> [[SQRT]]
112;
113  %sqrt = tail call <3 x float> @_Z4sqrtDv3_f(<3 x float> %arg)
114  ret <3 x float> %sqrt
115}
116
117define <4 x float> @test_sqrt_cr_v4f32(<4 x float> %arg) {
118; CHECK-LABEL: define <4 x float> @test_sqrt_cr_v4f32
119; CHECK-SAME: (<4 x float> [[ARG:%.*]]) {
120; CHECK-NEXT:    [[SQRT:%.*]] = tail call <4 x float> @llvm.sqrt.v4f32(<4 x float> [[ARG]])
121; CHECK-NEXT:    ret <4 x float> [[SQRT]]
122;
123  %sqrt = tail call <4 x float> @_Z4sqrtDv4_f(<4 x float> %arg)
124  ret <4 x float> %sqrt
125}
126
127define <8 x float> @test_sqrt_cr_v8f32(<8 x float> %arg) {
128; CHECK-LABEL: define <8 x float> @test_sqrt_cr_v8f32
129; CHECK-SAME: (<8 x float> [[ARG:%.*]]) {
130; CHECK-NEXT:    [[SQRT:%.*]] = tail call <8 x float> @llvm.sqrt.v8f32(<8 x float> [[ARG]])
131; CHECK-NEXT:    ret <8 x float> [[SQRT]]
132;
133  %sqrt = tail call <8 x float> @_Z4sqrtDv8_f(<8 x float> %arg)
134  ret <8 x float> %sqrt
135}
136
137define <16 x float> @test_sqrt_cr_v16f32(<16 x float> %arg) {
138; CHECK-LABEL: define <16 x float> @test_sqrt_cr_v16f32
139; CHECK-SAME: (<16 x float> [[ARG:%.*]]) {
140; CHECK-NEXT:    [[SQRT:%.*]] = tail call <16 x float> @llvm.sqrt.v16f32(<16 x float> [[ARG]])
141; CHECK-NEXT:    ret <16 x float> [[SQRT]]
142;
143  %sqrt = tail call <16 x float> @_Z4sqrtDv16_f(<16 x float> %arg)
144  ret <16 x float> %sqrt
145}
146
147define double @test_sqrt_f64(double %arg) {
148; CHECK-LABEL: define double @test_sqrt_f64
149; CHECK-SAME: (double [[ARG:%.*]]) {
150; CHECK-NEXT:    [[SQRT:%.*]] = tail call double @llvm.sqrt.f64(double [[ARG]])
151; CHECK-NEXT:    ret double [[SQRT]]
152;
153  %sqrt = tail call double @_Z4sqrtd(double %arg)
154  ret double %sqrt
155}
156
157define <2 x double> @test_sqrt_v2f64(<2 x double> %arg) {
158; CHECK-LABEL: define <2 x double> @test_sqrt_v2f64
159; CHECK-SAME: (<2 x double> [[ARG:%.*]]) {
160; CHECK-NEXT:    [[SQRT:%.*]] = tail call <2 x double> @llvm.sqrt.v2f64(<2 x double> [[ARG]])
161; CHECK-NEXT:    ret <2 x double> [[SQRT]]
162;
163  %sqrt = tail call <2 x double> @_Z4sqrtDv2_d(<2 x double> %arg)
164  ret <2 x double> %sqrt
165}
166
167define <3 x double> @test_sqrt_v3f64(<3 x double> %arg) {
168; CHECK-LABEL: define <3 x double> @test_sqrt_v3f64
169; CHECK-SAME: (<3 x double> [[ARG:%.*]]) {
170; CHECK-NEXT:    [[SQRT:%.*]] = tail call <3 x double> @llvm.sqrt.v3f64(<3 x double> [[ARG]])
171; CHECK-NEXT:    ret <3 x double> [[SQRT]]
172;
173  %sqrt = tail call <3 x double> @_Z4sqrtDv3_d(<3 x double> %arg)
174  ret <3 x double> %sqrt
175}
176
177define <4 x double> @test_sqrt_v4f64(<4 x double> %arg) {
178; CHECK-LABEL: define <4 x double> @test_sqrt_v4f64
179; CHECK-SAME: (<4 x double> [[ARG:%.*]]) {
180; CHECK-NEXT:    [[SQRT:%.*]] = tail call <4 x double> @llvm.sqrt.v4f64(<4 x double> [[ARG]])
181; CHECK-NEXT:    ret <4 x double> [[SQRT]]
182;
183  %sqrt = tail call <4 x double> @_Z4sqrtDv4_d(<4 x double> %arg)
184  ret <4 x double> %sqrt
185}
186
187define <8 x double> @test_sqrt_v8f64(<8 x double> %arg) {
188; CHECK-LABEL: define <8 x double> @test_sqrt_v8f64
189; CHECK-SAME: (<8 x double> [[ARG:%.*]]) {
190; CHECK-NEXT:    [[SQRT:%.*]] = tail call <8 x double> @llvm.sqrt.v8f64(<8 x double> [[ARG]])
191; CHECK-NEXT:    ret <8 x double> [[SQRT]]
192;
193  %sqrt = tail call <8 x double> @_Z4sqrtDv8_d(<8 x double> %arg)
194  ret <8 x double> %sqrt
195}
196
197define <16 x double> @test_sqrt_v16f64(<16 x double> %arg) {
198; CHECK-LABEL: define <16 x double> @test_sqrt_v16f64
199; CHECK-SAME: (<16 x double> [[ARG:%.*]]) {
200; CHECK-NEXT:    [[SQRT:%.*]] = tail call <16 x double> @llvm.sqrt.v16f64(<16 x double> [[ARG]])
201; CHECK-NEXT:    ret <16 x double> [[SQRT]]
202;
203  %sqrt = tail call <16 x double> @_Z4sqrtDv16_d(<16 x double> %arg)
204  ret <16 x double> %sqrt
205}
206
207define half @test_sqrt_f16(half %arg) {
208; CHECK-LABEL: define half @test_sqrt_f16
209; CHECK-SAME: (half [[ARG:%.*]]) {
210; CHECK-NEXT:    [[SQRT:%.*]] = tail call half @llvm.sqrt.f16(half [[ARG]])
211; CHECK-NEXT:    ret half [[SQRT]]
212;
213  %sqrt = tail call half @_Z4sqrtDh(half %arg)
214  ret half %sqrt
215}
216
217define <2 x half> @test_sqrt_v2f16(<2 x half> %arg) {
218; CHECK-LABEL: define <2 x half> @test_sqrt_v2f16
219; CHECK-SAME: (<2 x half> [[ARG:%.*]]) {
220; CHECK-NEXT:    [[SQRT:%.*]] = tail call <2 x half> @llvm.sqrt.v2f16(<2 x half> [[ARG]])
221; CHECK-NEXT:    ret <2 x half> [[SQRT]]
222;
223  %sqrt = tail call <2 x half> @_Z4sqrtDv2_Dh(<2 x half> %arg)
224  ret <2 x half> %sqrt
225}
226
227define <3 x half> @test_sqrt_v3f16(<3 x half> %arg) {
228; CHECK-LABEL: define <3 x half> @test_sqrt_v3f16
229; CHECK-SAME: (<3 x half> [[ARG:%.*]]) {
230; CHECK-NEXT:    [[SQRT:%.*]] = tail call <3 x half> @llvm.sqrt.v3f16(<3 x half> [[ARG]])
231; CHECK-NEXT:    ret <3 x half> [[SQRT]]
232;
233  %sqrt = tail call <3 x half> @_Z4sqrtDv3_Dh(<3 x half> %arg)
234  ret <3 x half> %sqrt
235}
236
237define <4 x half> @test_sqrt_v4f16(<4 x half> %arg) {
238; CHECK-LABEL: define <4 x half> @test_sqrt_v4f16
239; CHECK-SAME: (<4 x half> [[ARG:%.*]]) {
240; CHECK-NEXT:    [[SQRT:%.*]] = tail call <4 x half> @llvm.sqrt.v4f16(<4 x half> [[ARG]])
241; CHECK-NEXT:    ret <4 x half> [[SQRT]]
242;
243  %sqrt = tail call <4 x half> @_Z4sqrtDv4_Dh(<4 x half> %arg)
244  ret <4 x half> %sqrt
245}
246
247define <8 x half> @test_sqrt_v8f16(<8 x half> %arg) {
248; CHECK-LABEL: define <8 x half> @test_sqrt_v8f16
249; CHECK-SAME: (<8 x half> [[ARG:%.*]]) {
250; CHECK-NEXT:    [[SQRT:%.*]] = tail call <8 x half> @llvm.sqrt.v8f16(<8 x half> [[ARG]])
251; CHECK-NEXT:    ret <8 x half> [[SQRT]]
252;
253  %sqrt = tail call <8 x half> @_Z4sqrtDv8_Dh(<8 x half> %arg)
254  ret <8 x half> %sqrt
255}
256
257define <16 x half> @test_sqrt_v16f16(<16 x half> %arg) {
258; CHECK-LABEL: define <16 x half> @test_sqrt_v16f16
259; CHECK-SAME: (<16 x half> [[ARG:%.*]]) {
260; CHECK-NEXT:    [[SQRT:%.*]] = tail call <16 x half> @llvm.sqrt.v16f16(<16 x half> [[ARG]])
261; CHECK-NEXT:    ret <16 x half> [[SQRT]]
262;
263  %sqrt = tail call <16 x half> @_Z4sqrtDv16_Dh(<16 x half> %arg)
264  ret <16 x half> %sqrt
265}
266
267define float @test_sqrt_f32_nobuiltin_callsite(float %arg) {
268; CHECK-LABEL: define float @test_sqrt_f32_nobuiltin_callsite
269; CHECK-SAME: (float [[ARG:%.*]]) {
270; CHECK-NEXT:    [[SQRT:%.*]] = tail call float @_Z4sqrtf(float [[ARG]]) #[[ATTR3:[0-9]+]], !fpmath [[META0]]
271; CHECK-NEXT:    ret float [[SQRT]]
272;
273  %sqrt = tail call float @_Z4sqrtf(float %arg) #0, !fpmath !0
274  ret float %sqrt
275}
276
277define <2 x float> @test_sqrt_v2f32_nobuiltin_callsite(<2 x float> %arg) {
278; CHECK-LABEL: define <2 x float> @test_sqrt_v2f32_nobuiltin_callsite
279; CHECK-SAME: (<2 x float> [[ARG:%.*]]) {
280; CHECK-NEXT:    [[SQRT:%.*]] = tail call <2 x float> @_Z4sqrtDv2_f(<2 x float> [[ARG]]) #[[ATTR3]], !fpmath [[META0]]
281; CHECK-NEXT:    ret <2 x float> [[SQRT]]
282;
283  %sqrt = tail call <2 x float> @_Z4sqrtDv2_f(<2 x float> %arg) #0, !fpmath !0
284  ret <2 x float> %sqrt
285}
286
287define float @test_sqrt_cr_f32_nobuiltin_callsite(float %arg) {
288; CHECK-LABEL: define float @test_sqrt_cr_f32_nobuiltin_callsite
289; CHECK-SAME: (float [[ARG:%.*]]) {
290; CHECK-NEXT:    [[SQRT:%.*]] = tail call float @_Z4sqrtf(float [[ARG]]) #[[ATTR3]]
291; CHECK-NEXT:    ret float [[SQRT]]
292;
293  %sqrt = tail call float @_Z4sqrtf(float %arg) #0
294  ret float %sqrt
295}
296
297define <2 x float> @test_sqrt_cr_v2f32_nobuiltin_callsite(<2 x float> %arg) {
298; CHECK-LABEL: define <2 x float> @test_sqrt_cr_v2f32_nobuiltin_callsite
299; CHECK-SAME: (<2 x float> [[ARG:%.*]]) {
300; CHECK-NEXT:    [[SQRT:%.*]] = tail call <2 x float> @_Z4sqrtDv2_f(<2 x float> [[ARG]]) #[[ATTR3]]
301; CHECK-NEXT:    ret <2 x float> [[SQRT]]
302;
303  %sqrt = tail call <2 x float> @_Z4sqrtDv2_f(<2 x float> %arg) #0
304  ret <2 x float> %sqrt
305}
306
307; "no-builtins" should be ignored
308define float @test_sqrt_f32_nobuiltins(float %arg) #1 {
309; CHECK-LABEL: define float @test_sqrt_f32_nobuiltins
310; CHECK-SAME: (float [[ARG:%.*]]) #[[ATTR0:[0-9]+]] {
311; CHECK-NEXT:    [[SQRT:%.*]] = tail call float @_Z4sqrtf(float [[ARG]]) #[[ATTR3]], !fpmath [[META0]]
312; CHECK-NEXT:    ret float [[SQRT]]
313;
314  %sqrt = tail call float @_Z4sqrtf(float %arg) #0, !fpmath !0
315  ret float %sqrt
316}
317
318define <2 x float> @test_sqrt_v2f32_nobuiltins(<2 x float> %arg) #1 {
319; CHECK-LABEL: define <2 x float> @test_sqrt_v2f32_nobuiltins
320; CHECK-SAME: (<2 x float> [[ARG:%.*]]) #[[ATTR0]] {
321; CHECK-NEXT:    [[SQRT:%.*]] = tail call <2 x float> @_Z4sqrtDv2_f(<2 x float> [[ARG]]) #[[ATTR3]], !fpmath [[META0]]
322; CHECK-NEXT:    ret <2 x float> [[SQRT]]
323;
324  %sqrt = tail call <2 x float> @_Z4sqrtDv2_f(<2 x float> %arg) #0, !fpmath !0
325  ret <2 x float> %sqrt
326}
327
328define float @test_sqrt_cr_f32_nobuiltins(float %arg) #1 {
329; CHECK-LABEL: define float @test_sqrt_cr_f32_nobuiltins
330; CHECK-SAME: (float [[ARG:%.*]]) #[[ATTR0]] {
331; CHECK-NEXT:    [[SQRT:%.*]] = tail call float @_Z4sqrtf(float [[ARG]]) #[[ATTR3]]
332; CHECK-NEXT:    ret float [[SQRT]]
333;
334  %sqrt = tail call float @_Z4sqrtf(float %arg) #0
335  ret float %sqrt
336}
337
338define <2 x float> @test_sqrt_cr_v2f32_nobuiltins(<2 x float> %arg) #1 {
339; CHECK-LABEL: define <2 x float> @test_sqrt_cr_v2f32_nobuiltins
340; CHECK-SAME: (<2 x float> [[ARG:%.*]]) #[[ATTR0]] {
341; CHECK-NEXT:    [[SQRT:%.*]] = tail call <2 x float> @_Z4sqrtDv2_f(<2 x float> [[ARG]]) #[[ATTR3]]
342; CHECK-NEXT:    ret <2 x float> [[SQRT]]
343;
344  %sqrt = tail call <2 x float> @_Z4sqrtDv2_f(<2 x float> %arg) #0
345  ret <2 x float> %sqrt
346}
347
348define float @test_sqrt_f32_preserve_flags(float %arg) {
349; CHECK-LABEL: define float @test_sqrt_f32_preserve_flags
350; CHECK-SAME: (float [[ARG:%.*]]) {
351; CHECK-NEXT:    [[SQRT:%.*]] = tail call nnan ninf float @llvm.sqrt.f32(float [[ARG]]), !fpmath [[META0]]
352; CHECK-NEXT:    ret float [[SQRT]]
353;
354  %sqrt = tail call nnan ninf float @_Z4sqrtf(float %arg), !fpmath !0
355  ret float %sqrt
356}
357
358define <2 x float> @test_sqrt_v2f32_preserve_flags(<2 x float> %arg) {
359; CHECK-LABEL: define <2 x float> @test_sqrt_v2f32_preserve_flags
360; CHECK-SAME: (<2 x float> [[ARG:%.*]]) {
361; CHECK-NEXT:    [[SQRT:%.*]] = tail call nnan nsz contract <2 x float> @llvm.sqrt.v2f32(<2 x float> [[ARG]]), !fpmath [[META0]]
362; CHECK-NEXT:    ret <2 x float> [[SQRT]]
363;
364  %sqrt = tail call contract nsz nnan <2 x float> @_Z4sqrtDv2_f(<2 x float> %arg), !fpmath !0
365  ret <2 x float> %sqrt
366}
367
368define float @test_sqrt_f32_preserve_flags_md(float %arg) {
369; CHECK-LABEL: define float @test_sqrt_f32_preserve_flags_md
370; CHECK-SAME: (float [[ARG:%.*]]) {
371; CHECK-NEXT:    [[SQRT:%.*]] = tail call nnan ninf float @llvm.sqrt.f32(float [[ARG]]), !fpmath [[META0]], !foo [[META1:![0-9]+]]
372; CHECK-NEXT:    ret float [[SQRT]]
373;
374  %sqrt = tail call nnan ninf float @_Z4sqrtf(float %arg), !fpmath !0, !foo !1
375  ret float %sqrt
376}
377
378define <2 x float> @test_sqrt_v2f32_preserve_flags_md(<2 x float> %arg) {
379; CHECK-LABEL: define <2 x float> @test_sqrt_v2f32_preserve_flags_md
380; CHECK-SAME: (<2 x float> [[ARG:%.*]]) {
381; CHECK-NEXT:    [[SQRT:%.*]] = tail call nnan nsz contract <2 x float> @llvm.sqrt.v2f32(<2 x float> [[ARG]]), !fpmath [[META0]], !foo [[META1]]
382; CHECK-NEXT:    ret <2 x float> [[SQRT]]
383;
384  %sqrt = tail call contract nsz nnan <2 x float> @_Z4sqrtDv2_f(<2 x float> %arg), !fpmath !0, !foo !1
385  ret <2 x float> %sqrt
386}
387
388define float @test_sqrt_cr_f32_preserve_flags(float %arg) {
389; CHECK-LABEL: define float @test_sqrt_cr_f32_preserve_flags
390; CHECK-SAME: (float [[ARG:%.*]]) {
391; CHECK-NEXT:    [[SQRT:%.*]] = tail call ninf contract float @llvm.sqrt.f32(float [[ARG]])
392; CHECK-NEXT:    ret float [[SQRT]]
393;
394  %sqrt = tail call ninf contract float @_Z4sqrtf(float %arg)
395  ret float %sqrt
396}
397
398define <2 x float> @test_sqrt_cr_v2f32_preserve_flags(<2 x float> %arg) {
399; CHECK-LABEL: define <2 x float> @test_sqrt_cr_v2f32_preserve_flags
400; CHECK-SAME: (<2 x float> [[ARG:%.*]]) {
401; CHECK-NEXT:    [[SQRT:%.*]] = tail call nnan nsz <2 x float> @llvm.sqrt.v2f32(<2 x float> [[ARG]])
402; CHECK-NEXT:    ret <2 x float> [[SQRT]]
403;
404  %sqrt = tail call nnan nsz <2 x float> @_Z4sqrtDv2_f(<2 x float> %arg)
405  ret <2 x float> %sqrt
406}
407
408; Test the libm name, not a recognized opencl builtin.
409declare float @sqrtf(float) #2
410declare double @sqrt(double) #2
411
412define float @test_libm_sqrt_f32(float %arg) {
413; CHECK-LABEL: define float @test_libm_sqrt_f32
414; CHECK-SAME: (float [[ARG:%.*]]) {
415; CHECK-NEXT:    [[SQRT:%.*]] = tail call float @sqrtf(float [[ARG]])
416; CHECK-NEXT:    ret float [[SQRT]]
417;
418  %sqrt = tail call float @sqrtf(float %arg)
419  ret float %sqrt
420}
421
422define float @test_libm_sqrt_f32_fpmath(float %arg) {
423; CHECK-LABEL: define float @test_libm_sqrt_f32_fpmath
424; CHECK-SAME: (float [[ARG:%.*]]) {
425; CHECK-NEXT:    [[SQRT:%.*]] = tail call float @sqrtf(float [[ARG]]), !fpmath [[META0]]
426; CHECK-NEXT:    ret float [[SQRT]]
427;
428  %sqrt = tail call float @sqrtf(float %arg), !fpmath !0
429  ret float %sqrt
430}
431
432define double @test_libm_sqrt_f64(double %arg) {
433; CHECK-LABEL: define double @test_libm_sqrt_f64
434; CHECK-SAME: (double [[ARG:%.*]]) {
435; CHECK-NEXT:    [[SQRT:%.*]] = tail call double @sqrt(double [[ARG]])
436; CHECK-NEXT:    ret double [[SQRT]]
437;
438  %sqrt = tail call double @sqrt(double %arg)
439  ret double %sqrt
440}
441
442define double @test_libm_sqrt_f64_fpmath(double %arg) {
443; CHECK-LABEL: define double @test_libm_sqrt_f64_fpmath
444; CHECK-SAME: (double [[ARG:%.*]]) {
445; CHECK-NEXT:    [[SQRT:%.*]] = tail call double @sqrt(double [[ARG]]), !fpmath [[META0]]
446; CHECK-NEXT:    ret double [[SQRT]]
447;
448  %sqrt = tail call double @sqrt(double %arg), !fpmath !0
449  ret double %sqrt
450}
451
452attributes #0 = { nobuiltin }
453attributes #1 = { "no-builtins" }
454attributes #2 = { nounwind memory(none) }
455
456!0 = !{float 3.000000e+00}
457!1 = !{i32 1234}
458