xref: /llvm-project/clang/test/CodeGenHLSL/builtins/rcp.hlsl (revision 762f1b17b2815ccdfb4e5cb5412cb6210db92f73)
1// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple \
2// RUN:   dxil-pc-shadermodel6.3-library %s -fnative-half-type \
3// RUN:   -emit-llvm -disable-llvm-passes -o - | FileCheck %s \
4// RUN:   --check-prefixes=CHECK,DXIL_CHECK,DXIL_NATIVE_HALF,NATIVE_HALF
5// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple \
6// RUN:   dxil-pc-shadermodel6.3-library %s -emit-llvm -disable-llvm-passes \
7// RUN:   -o - | FileCheck %s --check-prefixes=CHECK,DXIL_CHECK,NO_HALF,DXIL_NO_HALF
8// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple \
9// RUN:   spirv-unknown-vulkan-compute %s -fnative-half-type \
10// RUN:   -emit-llvm -disable-llvm-passes -o - | FileCheck %s \
11// RUN:   --check-prefixes=CHECK,NATIVE_HALF,SPIR_NATIVE_HALF,SPIR_CHECK
12// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple \
13// RUN:   spirv-unknown-vulkan-compute %s -emit-llvm -disable-llvm-passes \
14// RUN:   -o - | FileCheck %s --check-prefixes=CHECK,NO_HALF,SPIR_NO_HALF,SPIR_CHECK
15
16// DXIL_NATIVE_HALF: define noundef nofpclass(nan inf) half @
17// SPIR_NATIVE_HALF: define spir_func noundef nofpclass(nan inf) half @
18// NATIVE_HALF: %hlsl.rcp = fdiv reassoc nnan ninf nsz arcp afn half 0xH3C00, %{{.*}}
19// NATIVE_HALF: ret half %hlsl.rcp
20// DXIL_NO_HALF: define noundef nofpclass(nan inf) float @
21// SPIR_NO_HALF: define spir_func noundef nofpclass(nan inf) float @
22// NO_HALF: %hlsl.rcp = fdiv reassoc nnan ninf nsz arcp afn float 1.000000e+00, %{{.*}}
23// NO_HALF: ret float %hlsl.rcp
24half test_rcp_half(half p0) { return rcp(p0); }
25
26// DXIL_NATIVE_HALF: define noundef nofpclass(nan inf) <2 x half> @
27// SPIR_NATIVE_HALF: define spir_func noundef nofpclass(nan inf) <2 x half> @
28// NATIVE_HALF: %hlsl.rcp = fdiv reassoc nnan ninf nsz arcp afn <2 x half> splat (half  0xH3C00), %{{.*}}
29// NATIVE_HALF: ret <2 x half> %hlsl.rcp
30// DXIL_NO_HALF: define noundef nofpclass(nan inf) <2 x float> @
31// SPIR_NO_HALF: define spir_func noundef nofpclass(nan inf) <2 x float> @
32// NO_HALF: %hlsl.rcp = fdiv reassoc nnan ninf nsz arcp afn <2 x float> splat (float 1.000000e+00), %{{.*}}
33// NO_HALF: ret <2 x float> %hlsl.rcp
34half2 test_rcp_half2(half2 p0) { return rcp(p0); }
35
36// DXIL_NATIVE_HALF: define noundef nofpclass(nan inf) <3 x half> @
37// SPIR_NATIVE_HALF: define spir_func noundef nofpclass(nan inf) <3 x half> @
38// NATIVE_HALF: %hlsl.rcp = fdiv reassoc nnan ninf nsz arcp afn <3 x half> splat (half  0xH3C00), %{{.*}}
39// NATIVE_HALF: ret <3 x half> %hlsl.rcp
40// DXIL_NO_HALF: define noundef nofpclass(nan inf) <3 x float> @
41// SPIR_NO_HALF: define spir_func noundef nofpclass(nan inf) <3 x float> @
42// NO_HALF: %hlsl.rcp = fdiv reassoc nnan ninf nsz arcp afn <3 x float> splat (float 1.000000e+00), %{{.*}}
43// NO_HALF: ret <3 x float> %hlsl.rcp
44half3 test_rcp_half3(half3 p0) { return rcp(p0); }
45
46// DXIL_NATIVE_HALF: define noundef nofpclass(nan inf) <4 x half> @
47// SPIR_NATIVE_HALF: define spir_func noundef nofpclass(nan inf) <4 x half> @
48// NATIVE_HALF: %hlsl.rcp = fdiv reassoc nnan ninf nsz arcp afn <4 x half> splat (half  0xH3C00), %{{.*}}
49// NATIVE_HALF: ret <4 x half> %hlsl.rcp
50// DXIL_NO_HALF: define noundef nofpclass(nan inf) <4 x float> @
51// SPIR_NO_HALF: define spir_func noundef nofpclass(nan inf) <4 x float> @
52// NO_HALF: %hlsl.rcp = fdiv reassoc nnan ninf nsz arcp afn <4 x float> splat (float 1.000000e+00), %{{.*}}
53// NO_HALF: ret <4 x float> %hlsl.rcp
54half4 test_rcp_half4(half4 p0) { return rcp(p0); }
55
56// DXIL_CHECK: define noundef nofpclass(nan inf) float @
57// SPIR_CHECK: define spir_func noundef nofpclass(nan inf) float @
58// CHECK: %hlsl.rcp = fdiv reassoc nnan ninf nsz arcp afn float 1.000000e+00, %{{.*}}
59// CHECK: ret float %hlsl.rcp
60float test_rcp_float(float p0) { return rcp(p0); }
61
62// DXIL_CHECK: define noundef nofpclass(nan inf) <2 x float> @
63// SPIR_CHECK: define spir_func noundef nofpclass(nan inf) <2 x float> @
64// CHECK: %hlsl.rcp = fdiv reassoc nnan ninf nsz arcp afn <2 x float> splat (float 1.000000e+00), %{{.*}}
65// CHECK: ret <2 x float> %hlsl.rcp
66float2 test_rcp_float2(float2 p0) { return rcp(p0); }
67
68// DXIL_CHECK: define noundef nofpclass(nan inf) <3 x float> @
69// SPIR_CHECK: define spir_func noundef nofpclass(nan inf) <3 x float> @
70// CHECK: %hlsl.rcp = fdiv reassoc nnan ninf nsz arcp afn <3 x float> splat (float 1.000000e+00), %{{.*}}
71// CHECK: ret <3 x float> %hlsl.rcp
72float3 test_rcp_float3(float3 p0) { return rcp(p0); }
73
74// DXIL_CHECK: define noundef nofpclass(nan inf) <4 x float> @
75// SPIR_CHECK: define spir_func noundef nofpclass(nan inf) <4 x float> @
76// CHECK: %hlsl.rcp = fdiv reassoc nnan ninf nsz arcp afn <4 x float> splat (float 1.000000e+00), %{{.*}}
77// CHECK: ret <4 x float> %hlsl.rcp
78float4 test_rcp_float4(float4 p0) { return rcp(p0); }
79
80// DXIL_CHECK: define noundef nofpclass(nan inf) double @
81// SPIR_CHECK: define spir_func noundef nofpclass(nan inf) double @
82// CHECK: %hlsl.rcp = fdiv reassoc nnan ninf nsz arcp afn double 1.000000e+00, %{{.*}}
83// CHECK: ret double %hlsl.rcp
84double test_rcp_double(double p0) { return rcp(p0); }
85
86// DXIL_CHECK: define noundef nofpclass(nan inf) <2 x double> @
87// SPIR_CHECK: define spir_func noundef nofpclass(nan inf) <2 x double> @
88// CHECK: %hlsl.rcp = fdiv reassoc nnan ninf nsz arcp afn <2 x double> splat (double 1.000000e+00), %{{.*}}
89// CHECK: ret <2 x double> %hlsl.rcp
90double2 test_rcp_double2(double2 p0) { return rcp(p0); }
91
92// DXIL_CHECK: define noundef nofpclass(nan inf) <3 x double> @
93// SPIR_CHECK: define spir_func noundef nofpclass(nan inf) <3 x double> @
94// CHECK: %hlsl.rcp = fdiv reassoc nnan ninf nsz arcp afn <3 x double> splat (double 1.000000e+00), %{{.*}}
95// CHECK: ret <3 x double> %hlsl.rcp
96double3 test_rcp_double3(double3 p0) { return rcp(p0); }
97
98// DXIL_CHECK: define noundef nofpclass(nan inf) <4 x double> @
99// SPIR_CHECK: define spir_func noundef nofpclass(nan inf) <4 x double> @
100// CHECK: %hlsl.rcp = fdiv reassoc nnan ninf nsz arcp afn <4 x double> splat (double 1.000000e+00), %{{.*}}
101// CHECK: ret <4 x double> %hlsl.rcp
102double4 test_rcp_double4(double4 p0) { return rcp(p0); }
103