Debian Codegraph @

clang/test/CodeGenHLSL/builtins/dot2add.hlsl

raw
1 // RUN: %clang_cc1 -finclude-default-header -fnative-half-type -fnative-int16-type -triple \
2 // RUN: dxil-pc-shadermodel6.4-compute %s -emit-llvm -o - | \
3 // RUN: FileCheck %s --check-prefixes=CHECK,CHECK-DXIL
4 // RUN: %clang_cc1 -finclude-default-header -fnative-half-type -fnative-int16-type -triple \
5 // RUN: spirv-pc-vulkan-compute %s -emit-llvm -o - | \
6 // RUN: FileCheck %s --check-prefixes=CHECK,CHECK-SPIRV
7
8 // Test basic lowering to runtime function call.
9
10 // CHECK-LABEL: define {{.*}}test_default_parameter_type
11 float test_default_parameter_type(half2 p1, half2 p2, float p3) {
12 // CHECK-SPIRV: %[[MUL:.*]] = call reassoc nnan ninf nsz arcp afn half @llvm.spv.fdot.v2f16(<2 x half> %{{.*}}, <2 x half> %{{.*}})
13 // CHECK-SPIRV: %[[CONV:.*]] = fpext reassoc nnan ninf nsz arcp afn half %[[MUL]] to float
14 // CHECK-SPIRV: %[[C:.*]] = load float, ptr %c.addr.i, align 4
15 // CHECK-SPIRV: %[[RES:.*]] = fadd reassoc nnan ninf nsz arcp afn float %[[CONV]], %[[C]]
16 // CHECK-DXIL: %[[AX:.*]] = extractelement <2 x half> %{{.*}}, i32 0
17 // CHECK-DXIL: %[[AY:.*]] = extractelement <2 x half> %{{.*}}, i32 1
18 // CHECK-DXIL: %[[BX:.*]] = extractelement <2 x half> %{{.*}}, i32 0
19 // CHECK-DXIL: %[[BY:.*]] = extractelement <2 x half> %{{.*}}, i32 1
20 // CHECK-DXIL: %[[RES:.*]] = call {{.*}} float @llvm.dx.dot2add(float %{{.*}}, half %[[AX]], half %[[AY]], half %[[BX]], half %[[BY]])
21 // CHECK: ret float %[[RES]]
22 return dot2add(p1, p2, p3);
23 }
24
25 // CHECK-LABEL: define {{.*}}test_float_arg2_type
26 float test_float_arg2_type(half2 p1, float2 p2, float p3) {
27 // CHECK: %conv = fptrunc reassoc nnan ninf nsz arcp afn <2 x float> %{{.*}} to <2 x half>
28 // CHECK-SPIRV: %[[MUL:.*]] = call reassoc nnan ninf nsz arcp afn half @llvm.spv.fdot.v2f16(<2 x half> %{{.*}}, <2 x half> %{{.*}})
29 // CHECK-SPIRV: %[[CONV:.*]] = fpext reassoc nnan ninf nsz arcp afn half %[[MUL]] to float
30 // CHECK-SPIRV: %[[C:.*]] = load float, ptr %c.addr.i, align 4
31 // CHECK-SPIRV: %[[RES:.*]] = fadd reassoc nnan ninf nsz arcp afn float %[[CONV]], %[[C]]
32 // CHECK-DXIL: %[[AX:.*]] = extractelement <2 x half> %{{.*}}, i32 0
33 // CHECK-DXIL: %[[AY:.*]] = extractelement <2 x half> %{{.*}}, i32 1
34 // CHECK-DXIL: %[[BX:.*]] = extractelement <2 x half> %{{.*}}, i32 0
35 // CHECK-DXIL: %[[BY:.*]] = extractelement <2 x half> %{{.*}}, i32 1
36 // CHECK-DXIL: %[[RES:.*]] = call {{.*}} float @llvm.dx.dot2add(float %{{.*}}, half %[[AX]], half %[[AY]], half %[[BX]], half %[[BY]])
37 // CHECK: ret float %[[RES]]
38 return dot2add(p1, p2, p3);
39 }
40
41 // CHECK-LABEL: define {{.*}}test_float_arg1_type
42 float test_float_arg1_type(float2 p1, half2 p2, float p3) {
43 // CHECK: %conv = fptrunc reassoc nnan ninf nsz arcp afn <2 x float> %{{.*}} to <2 x half>
44 // CHECK-SPIRV: %[[MUL:.*]] = call reassoc nnan ninf nsz arcp afn half @llvm.spv.fdot.v2f16(<2 x half> %{{.*}}, <2 x half> %{{.*}})
45 // CHECK-SPIRV: %[[CONV:.*]] = fpext reassoc nnan ninf nsz arcp afn half %[[MUL]] to float
46 // CHECK-SPIRV: %[[C:.*]] = load float, ptr %c.addr.i, align 4
47 // CHECK-SPIRV: %[[RES:.*]] = fadd reassoc nnan ninf nsz arcp afn float %[[CONV]], %[[C]]
48 // CHECK-DXIL: %[[AX:.*]] = extractelement <2 x half> %{{.*}}, i32 0
49 // CHECK-DXIL: %[[AY:.*]] = extractelement <2 x half> %{{.*}}, i32 1
50 // CHECK-DXIL: %[[BX:.*]] = extractelement <2 x half> %{{.*}}, i32 0
51 // CHECK-DXIL: %[[BY:.*]] = extractelement <2 x half> %{{.*}}, i32 1
52 // CHECK-DXIL: %[[RES:.*]] = call {{.*}} float @llvm.dx.dot2add(float %{{.*}}, half %[[AX]], half %[[AY]], half %[[BX]], half %[[BY]])
53 // CHECK: ret float %[[RES]]
54 return dot2add(p1, p2, p3);
55 }
56
57 // CHECK-LABEL: define {{.*}}test_double_arg3_type
58 float test_double_arg3_type(half2 p1, half2 p2, double p3) {
59 // CHECK: %conv = fptrunc reassoc nnan ninf nsz arcp afn double %{{.*}} to float
60 // CHECK-SPIRV: %[[MUL:.*]] = call reassoc nnan ninf nsz arcp afn half @llvm.spv.fdot.v2f16(<2 x half> %{{.*}}, <2 x half> %{{.*}})
61 // CHECK-SPIRV: %[[CONV:.*]] = fpext reassoc nnan ninf nsz arcp afn half %[[MUL]] to float
62 // CHECK-SPIRV: %[[C:.*]] = load float, ptr %c.addr.i, align 4
63 // CHECK-SPIRV: %[[RES:.*]] = fadd reassoc nnan ninf nsz arcp afn float %[[CONV]], %[[C]]
64 // CHECK-DXIL: %[[AX:.*]] = extractelement <2 x half> %{{.*}}, i32 0
65 // CHECK-DXIL: %[[AY:.*]] = extractelement <2 x half> %{{.*}}, i32 1
66 // CHECK-DXIL: %[[BX:.*]] = extractelement <2 x half> %{{.*}}, i32 0
67 // CHECK-DXIL: %[[BY:.*]] = extractelement <2 x half> %{{.*}}, i32 1
68 // CHECK-DXIL: %[[RES:.*]] = call {{.*}} float @llvm.dx.dot2add(float %{{.*}}, half %[[AX]], half %[[AY]], half %[[BX]], half %[[BY]])
69 // CHECK: ret float %[[RES]]
70 return dot2add(p1, p2, p3);
71 }
72
73 // CHECK-LABEL: define {{.*}}test_float_arg1_arg2_type
74 float test_float_arg1_arg2_type(float2 p1, float2 p2, float p3) {
75 // CHECK: %conv = fptrunc reassoc nnan ninf nsz arcp afn <2 x float> %{{.*}} to <2 x half>
76 // CHECK: %conv1 = fptrunc reassoc nnan ninf nsz arcp afn <2 x float> %{{.*}} to <2 x half>
77 // CHECK-SPIRV: %[[MUL:.*]] = call reassoc nnan ninf nsz arcp afn half @llvm.spv.fdot.v2f16(<2 x half> %{{.*}}, <2 x half> %{{.*}})
78 // CHECK-SPIRV: %[[CONV:.*]] = fpext reassoc nnan ninf nsz arcp afn half %[[MUL]] to float
79 // CHECK-SPIRV: %[[C:.*]] = load float, ptr %c.addr.i, align 4
80 // CHECK-SPIRV: %[[RES:.*]] = fadd reassoc nnan ninf nsz arcp afn float %[[CONV]], %[[C]]
81 // CHECK-DXIL: %[[AX:.*]] = extractelement <2 x half> %{{.*}}, i32 0
82 // CHECK-DXIL: %[[AY:.*]] = extractelement <2 x half> %{{.*}}, i32 1
83 // CHECK-DXIL: %[[BX:.*]] = extractelement <2 x half> %{{.*}}, i32 0
84 // CHECK-DXIL: %[[BY:.*]] = extractelement <2 x half> %{{.*}}, i32 1
85 // CHECK-DXIL: %[[RES:.*]] = call {{.*}} float @llvm.dx.dot2add(float %{{.*}}, half %[[AX]], half %[[AY]], half %[[BX]], half %[[BY]])
86 // CHECK: ret float %[[RES]]
87 return dot2add(p1, p2, p3);
88 }
89
90 // CHECK-LABEL: define {{.*}}test_double_arg1_arg2_type
91 float test_double_arg1_arg2_type(double2 p1, double2 p2, float p3) {
92 // CHECK: %conv = fptrunc reassoc nnan ninf nsz arcp afn <2 x double> %{{.*}} to <2 x half>
93 // CHECK: %conv1 = fptrunc reassoc nnan ninf nsz arcp afn <2 x double> %{{.*}} to <2 x half>
94 // CHECK-SPIRV: %[[MUL:.*]] = call reassoc nnan ninf nsz arcp afn half @llvm.spv.fdot.v2f16(<2 x half> %{{.*}}, <2 x half> %{{.*}})
95 // CHECK-SPIRV: %[[CONV:.*]] = fpext reassoc nnan ninf nsz arcp afn half %[[MUL]] to float
96 // CHECK-SPIRV: %[[C:.*]] = load float, ptr %c.addr.i, align 4
97 // CHECK-SPIRV: %[[RES:.*]] = fadd reassoc nnan ninf nsz arcp afn float %[[CONV]], %[[C]]
98 // CHECK-DXIL: %[[AX:.*]] = extractelement <2 x half> %{{.*}}, i32 0
99 // CHECK-DXIL: %[[AY:.*]] = extractelement <2 x half> %{{.*}}, i32 1
100 // CHECK-DXIL: %[[BX:.*]] = extractelement <2 x half> %{{.*}}, i32 0
101 // CHECK-DXIL: %[[BY:.*]] = extractelement <2 x half> %{{.*}}, i32 1
102 // CHECK-DXIL: %[[RES:.*]] = call {{.*}} float @llvm.dx.dot2add(float %{{.*}}, half %[[AX]], half %[[AY]], half %[[BX]], half %[[BY]])
103 // CHECK: ret float %[[RES]]
104 return dot2add(p1, p2, p3);
105 }
106
107 // CHECK-LABEL: define {{.*}}test_int16_arg1_arg2_type
108 float test_int16_arg1_arg2_type(int16_t2 p1, int16_t2 p2, float p3) {
109 // CHECK: %conv = sitofp <2 x i16> %{{.*}} to <2 x half>
110 // CHECK: %conv1 = sitofp <2 x i16> %{{.*}} to <2 x half>
111 // CHECK-SPIRV: %[[MUL:.*]] = call reassoc nnan ninf nsz arcp afn half @llvm.spv.fdot.v2f16(<2 x half> %{{.*}}, <2 x half> %{{.*}})
112 // CHECK-SPIRV: %[[CONV:.*]] = fpext reassoc nnan ninf nsz arcp afn half %[[MUL]] to float
113 // CHECK-SPIRV: %[[C:.*]] = load float, ptr %c.addr.i, align 4
114 // CHECK-SPIRV: %[[RES:.*]] = fadd reassoc nnan ninf nsz arcp afn float %[[CONV]], %[[C]]
115 // CHECK-DXIL: %[[AX:.*]] = extractelement <2 x half> %{{.*}}, i32 0
116 // CHECK-DXIL: %[[AY:.*]] = extractelement <2 x half> %{{.*}}, i32 1
117 // CHECK-DXIL: %[[BX:.*]] = extractelement <2 x half> %{{.*}}, i32 0
118 // CHECK-DXIL: %[[BY:.*]] = extractelement <2 x half> %{{.*}}, i32 1
119 // CHECK-DXIL: %[[RES:.*]] = call {{.*}} float @llvm.dx.dot2add(float %{{.*}}, half %[[AX]], half %[[AY]], half %[[BX]], half %[[BY]])
120 // CHECK: ret float %[[RES]]
121 return dot2add(p1, p2, p3);
122 }
123
124 // CHECK-LABEL: define {{.*}}test_int32_arg1_arg2_type
125 float test_int32_arg1_arg2_type(int32_t2 p1, int32_t2 p2, float p3) {
126 // CHECK: %conv = sitofp <2 x i32> %{{.*}} to <2 x half>
127 // CHECK: %conv1 = sitofp <2 x i32> %{{.*}} to <2 x half>
128 // CHECK-SPIRV: %[[MUL:.*]] = call reassoc nnan ninf nsz arcp afn half @llvm.spv.fdot.v2f16(<2 x half> %{{.*}}, <2 x half> %{{.*}})
129 // CHECK-SPIRV: %[[CONV:.*]] = fpext reassoc nnan ninf nsz arcp afn half %[[MUL]] to float
130 // CHECK-SPIRV: %[[C:.*]] = load float, ptr %c.addr.i, align 4
131 // CHECK-SPIRV: %[[RES:.*]] = fadd reassoc nnan ninf nsz arcp afn float %[[CONV]], %[[C]]
132 // CHECK-DXIL: %[[AX:.*]] = extractelement <2 x half> %{{.*}}, i32 0
133 // CHECK-DXIL: %[[AY:.*]] = extractelement <2 x half> %{{.*}}, i32 1
134 // CHECK-DXIL: %[[BX:.*]] = extractelement <2 x half> %{{.*}}, i32 0
135 // CHECK-DXIL: %[[BY:.*]] = extractelement <2 x half> %{{.*}}, i32 1
136 // CHECK-DXIL: %[[RES:.*]] = call {{.*}} float @llvm.dx.dot2add(float %{{.*}}, half %[[AX]], half %[[AY]], half %[[BX]], half %[[BY]])
137 // CHECK: ret float %[[RES]]
138 return dot2add(p1, p2, p3);
139 }
140
141 // CHECK-LABEL: define {{.*}}test_int64_arg1_arg2_type
142 float test_int64_arg1_arg2_type(int64_t2 p1, int64_t2 p2, float p3) {
143 // CHECK: %conv = sitofp <2 x i64> %{{.*}} to <2 x half>
144 // CHECK: %conv1 = sitofp <2 x i64> %{{.*}} to <2 x half>
145 // CHECK-SPIRV: %[[MUL:.*]] = call reassoc nnan ninf nsz arcp afn half @llvm.spv.fdot.v2f16(<2 x half> %{{.*}}, <2 x half> %{{.*}})
146 // CHECK-SPIRV: %[[CONV:.*]] = fpext reassoc nnan ninf nsz arcp afn half %[[MUL]] to float
147 // CHECK-SPIRV: %[[C:.*]] = load float, ptr %c.addr.i, align 4
148 // CHECK-SPIRV: %[[RES:.*]] = fadd reassoc nnan ninf nsz arcp afn float %[[CONV]], %[[C]]
149 // CHECK-DXIL: %[[AX:.*]] = extractelement <2 x half> %{{.*}}, i32 0
150 // CHECK-DXIL: %[[AY:.*]] = extractelement <2 x half> %{{.*}}, i32 1
151 // CHECK-DXIL: %[[BX:.*]] = extractelement <2 x half> %{{.*}}, i32 0
152 // CHECK-DXIL: %[[BY:.*]] = extractelement <2 x half> %{{.*}}, i32 1
153 // CHECK-DXIL: %[[RES:.*]] = call {{.*}} float @llvm.dx.dot2add(float %{{.*}}, half %[[AX]], half %[[AY]], half %[[BX]], half %[[BY]])
154 // CHECK: ret float %[[RES]]
155 return dot2add(p1, p2, p3);
156 }
157
158 // CHECK-LABEL: define {{.*}}test_bool_arg1_arg2_type
159 float test_bool_arg1_arg2_type(bool2 p1, bool2 p2, float p3) {
160 // CHECK: %loadedv = trunc <2 x i32> %{{.*}} to <2 x i1>
161 // CHECK: %conv = uitofp <2 x i1> %loadedv to <2 x half>
162 // CHECK: %loadedv1 = trunc <2 x i32> %{{.*}} to <2 x i1>
163 // CHECK: %conv2 = uitofp <2 x i1> %loadedv1 to <2 x half>
164 // CHECK-SPIRV: %[[MUL:.*]] = call reassoc nnan ninf nsz arcp afn half @llvm.spv.fdot.v2f16(<2 x half> %{{.*}}, <2 x half> %{{.*}})
165 // CHECK-SPIRV: %[[CONV:.*]] = fpext reassoc nnan ninf nsz arcp afn half %[[MUL]] to float
166 // CHECK-SPIRV: %[[C:.*]] = load float, ptr %c.addr.i, align 4
167 // CHECK-SPIRV: %[[RES:.*]] = fadd reassoc nnan ninf nsz arcp afn float %[[CONV]], %[[C]]
168 // CHECK-DXIL: %[[AX:.*]] = extractelement <2 x half> %{{.*}}, i32 0
169 // CHECK-DXIL: %[[AY:.*]] = extractelement <2 x half> %{{.*}}, i32 1
170 // CHECK-DXIL: %[[BX:.*]] = extractelement <2 x half> %{{.*}}, i32 0
171 // CHECK-DXIL: %[[BY:.*]] = extractelement <2 x half> %{{.*}}, i32 1
172 // CHECK-DXIL: %[[RES:.*]] = call {{.*}} float @llvm.dx.dot2add(float %{{.*}}, half %[[AX]], half %[[AY]], half %[[BX]], half %[[BY]])
173 // CHECK: ret float %[[RES]]
174 return dot2add(p1, p2, p3);
175 }