xref: /llvm-project/clang/test/CodeGenHLSL/builtins/abs.hlsl (revision 762f1b17b2815ccdfb4e5cb5412cb6210db92f73)
1// RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel6.3-library %s \
2// RUN:  -fnative-half-type -emit-llvm -disable-llvm-passes -o - | \
3// RUN:  FileCheck %s --check-prefixes=CHECK,NATIVE_HALF
4// RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel6.3-library %s \
5// RUN:  -emit-llvm -disable-llvm-passes -o - | \
6// RUN:  FileCheck %s --check-prefixes=CHECK,NO_HALF
7
8using hlsl::abs;
9
10#ifdef __HLSL_ENABLE_16_BIT
11// NATIVE_HALF-LABEL: define noundef i16 @_Z16test_abs_int16_t
12// NATIVE_HALF: call i16 @llvm.abs.i16(
13int16_t test_abs_int16_t(int16_t p0) { return abs(p0); }
14// NATIVE_HALF-LABEL: define noundef <2 x i16> @_Z17test_abs_int16_t2
15// NATIVE_HALF: call <2 x i16> @llvm.abs.v2i16(
16int16_t2 test_abs_int16_t2(int16_t2 p0) { return abs(p0); }
17// NATIVE_HALF-LABEL: define noundef <3 x i16> @_Z17test_abs_int16_t3
18// NATIVE_HALF: call <3 x i16> @llvm.abs.v3i16(
19int16_t3 test_abs_int16_t3(int16_t3 p0) { return abs(p0); }
20// NATIVE_HALF-LABEL: define noundef <4 x i16> @_Z17test_abs_int16_t4
21// NATIVE_HALF: call <4 x i16> @llvm.abs.v4i16(
22int16_t4 test_abs_int16_t4(int16_t4 p0) { return abs(p0); }
23#endif // __HLSL_ENABLE_16_BIT
24
25// NATIVE_HALF-LABEL: define noundef nofpclass(nan inf) half @_Z13test_abs_half
26// NATIVE_HALF: call reassoc nnan ninf nsz arcp afn half @llvm.fabs.f16(
27// NO_HALF-LABEL: define noundef nofpclass(nan inf) float @_Z13test_abs_half
28// NO_HALF: call reassoc nnan ninf nsz arcp afn float @llvm.fabs.f32(float %0)
29half test_abs_half(half p0) { return abs(p0); }
30// NATIVE_HALF-LABEL: define noundef nofpclass(nan inf) <2 x half> @_Z14test_abs_half2
31// NATIVE_HALF: call reassoc nnan ninf nsz arcp afn <2 x half> @llvm.fabs.v2f16(
32// NO_HALF-LABEL: define noundef nofpclass(nan inf) <2 x float> @_Z14test_abs_half2
33// NO_HALF: call reassoc nnan ninf nsz arcp afn <2 x float> @llvm.fabs.v2f32(
34half2 test_abs_half2(half2 p0) { return abs(p0); }
35// NATIVE_HALF-LABEL: define noundef nofpclass(nan inf) <3 x half> @_Z14test_abs_half3
36// NATIVE_HALF: call reassoc nnan ninf nsz arcp afn <3 x half> @llvm.fabs.v3f16(
37// NO_HALF-LABEL: define noundef nofpclass(nan inf) <3 x float> @_Z14test_abs_half3
38// NO_HALF: call reassoc nnan ninf nsz arcp afn <3 x float> @llvm.fabs.v3f32(
39half3 test_abs_half3(half3 p0) { return abs(p0); }
40// NATIVE_HALF-LABEL: define noundef nofpclass(nan inf) <4 x half> @_Z14test_abs_half4
41// NATIVE_HALF: call reassoc nnan ninf nsz arcp afn <4 x half> @llvm.fabs.v4f16(
42// NO_HALF-LABEL: define noundef nofpclass(nan inf) <4 x float> @_Z14test_abs_half4
43// NO_HALF: call reassoc nnan ninf nsz arcp afn <4 x float> @llvm.fabs.v4f32(
44half4 test_abs_half4(half4 p0) { return abs(p0); }
45
46// CHECK-LABEL: define noundef i32 @_Z12test_abs_int
47// CHECK: call i32 @llvm.abs.i32(
48int test_abs_int(int p0) { return abs(p0); }
49// CHECK-LABEL: define noundef <2 x i32> @_Z13test_abs_int2
50// CHECK: call <2 x i32> @llvm.abs.v2i32(
51int2 test_abs_int2(int2 p0) { return abs(p0); }
52// CHECK-LABEL: define noundef <3 x i32> @_Z13test_abs_int3
53// CHECK: call <3 x i32> @llvm.abs.v3i32(
54int3 test_abs_int3(int3 p0) { return abs(p0); }
55// CHECK-LABEL: define noundef <4 x i32> @_Z13test_abs_int4
56// CHECK: call <4 x i32> @llvm.abs.v4i32(
57int4 test_abs_int4(int4 p0) { return abs(p0); }
58
59// CHECK-LABEL: define noundef nofpclass(nan inf) float @_Z14test_abs_float
60// CHECK: call reassoc nnan ninf nsz arcp afn float @llvm.fabs.f32(
61float test_abs_float(float p0) { return abs(p0); }
62// CHECK-LABEL: define noundef nofpclass(nan inf) <2 x float> @_Z15test_abs_float2
63// CHECK: call reassoc nnan ninf nsz arcp afn <2 x float> @llvm.fabs.v2f32(
64float2 test_abs_float2(float2 p0) { return abs(p0); }
65// CHECK-LABEL: define noundef nofpclass(nan inf) <3 x float> @_Z15test_abs_float3
66// CHECK: call reassoc nnan ninf nsz arcp afn <3 x float> @llvm.fabs.v3f32(
67float3 test_abs_float3(float3 p0) { return abs(p0); }
68// CHECK-LABEL: define noundef nofpclass(nan inf) <4 x float> @_Z15test_abs_float4
69// CHECK: call reassoc nnan ninf nsz arcp afn <4 x float> @llvm.fabs.v4f32(
70float4 test_abs_float4(float4 p0) { return abs(p0); }
71
72// CHECK-LABEL: define noundef i64 @_Z16test_abs_int64_t
73// CHECK: call i64 @llvm.abs.i64(
74int64_t test_abs_int64_t(int64_t p0) { return abs(p0); }
75// CHECK-LABEL: define noundef <2 x i64> @_Z17test_abs_int64_t2
76// CHECK: call <2 x i64> @llvm.abs.v2i64(
77int64_t2 test_abs_int64_t2(int64_t2 p0) { return abs(p0); }
78// CHECK-LABEL: define noundef <3 x i64> @_Z17test_abs_int64_t3
79// CHECK: call <3 x i64> @llvm.abs.v3i64(
80int64_t3 test_abs_int64_t3(int64_t3 p0) { return abs(p0); }
81// CHECK-LABEL: define noundef <4 x i64> @_Z17test_abs_int64_t4
82// CHECK: call <4 x i64> @llvm.abs.v4i64(
83int64_t4 test_abs_int64_t4(int64_t4 p0) { return abs(p0); }
84
85// CHECK-LABEL: define noundef nofpclass(nan inf) double @_Z15test_abs_double
86// CHECK: call reassoc nnan ninf nsz arcp afn double @llvm.fabs.f64(
87double test_abs_double(double p0) { return abs(p0); }
88// CHECK-LABEL: define noundef nofpclass(nan inf) <2 x double> @_Z16test_abs_double2
89// CHECK: call reassoc nnan ninf nsz arcp afn <2 x double> @llvm.fabs.v2f64(
90double2 test_abs_double2(double2 p0) { return abs(p0); }
91// CHECK-LABEL: define noundef nofpclass(nan inf) <3 x double> @_Z16test_abs_double3
92// CHECK: call reassoc nnan ninf nsz arcp afn <3 x double> @llvm.fabs.v3f64(
93double3 test_abs_double3(double3 p0) { return abs(p0); }
94// CHECK-LABEL: define noundef nofpclass(nan inf) <4 x double> @_Z16test_abs_double4
95// CHECK: call reassoc nnan ninf nsz arcp afn <4 x double> @llvm.fabs.v4f64(
96double4 test_abs_double4(double4 p0) { return abs(p0); }
97