Debian Codegraph @

llvm/test/CodeGen/SPIRV/hlsl-intrinsics/faceforward.ll

raw
1 ; RUN: llc -O0 -verify-machineinstrs -mtriple=spirv-vulkan1.3-unknown %s -o - | FileCheck %s
2 ; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv-vulkan1.3-unknown %s -o - -filetype=obj | spirv-val --target-env vulkan1.3 %}
3
4 ; Make sure SPIRV operation function calls for faceforward are lowered correctly.
5
6 ; CHECK-DAG: %[[#op_ext_glsl:]] = OpExtInstImport "GLSL.std.450"
7 ; CHECK-DAG: %[[#float_16:]] = OpTypeFloat 16
8 ; CHECK-DAG: %[[#vec4_float_16:]] = OpTypeVector %[[#float_16]] 4
9 ; CHECK-DAG: %[[#float_32:]] = OpTypeFloat 32
10 ; CHECK-DAG: %[[#vec4_float_32:]] = OpTypeVector %[[#float_32]] 4
11
12 define internal noundef half @faceforward_half(half noundef %a, half noundef %b, half noundef %c) {
13 entry:
14 ; CHECK: %[[#]] = OpFunction %[[#float_16]] None %[[#]]
15 ; CHECK: %[[#arg0:]] = OpFunctionParameter %[[#float_16]]
16 ; CHECK: %[[#arg1:]] = OpFunctionParameter %[[#float_16]]
17 ; CHECK: %[[#arg2:]] = OpFunctionParameter %[[#float_16]]
18 ; CHECK: %[[#]] = OpExtInst %[[#float_16]] %[[#op_ext_glsl]] FaceForward %[[#arg0]] %[[#arg1]] %[[#arg2]]
19 %spv.faceforward = call half @llvm.spv.faceforward.f16(half %a, half %b, half %c)
20 ret half %spv.faceforward
21 }
22
23 define internal noundef float @faceforward_float(float noundef %a, float noundef %b, float noundef %c) {
24 entry:
25 ; CHECK: %[[#]] = OpFunction %[[#float_32]] None %[[#]]
26 ; CHECK: %[[#arg0:]] = OpFunctionParameter %[[#float_32]]
27 ; CHECK: %[[#arg1:]] = OpFunctionParameter %[[#float_32]]
28 ; CHECK: %[[#arg2:]] = OpFunctionParameter %[[#float_32]]
29 ; CHECK: %[[#]] = OpExtInst %[[#float_32]] %[[#op_ext_glsl]] FaceForward %[[#arg0]] %[[#arg1]] %[[#arg2]]
30 %spv.faceforward = call float @llvm.spv.faceforward.f32(float %a, float %b, float %c)
31 ret float %spv.faceforward
32 }
33
34 define internal noundef <4 x half> @faceforward_half4(<4 x half> noundef %a, <4 x half> noundef %b, <4 x half> noundef %c) {
35 entry:
36 ; CHECK: %[[#]] = OpFunction %[[#vec4_float_16]] None %[[#]]
37 ; CHECK: %[[#arg0:]] = OpFunctionParameter %[[#vec4_float_16]]
38 ; CHECK: %[[#arg1:]] = OpFunctionParameter %[[#vec4_float_16]]
39 ; CHECK: %[[#arg2:]] = OpFunctionParameter %[[#vec4_float_16]]
40 ; CHECK: %[[#]] = OpExtInst %[[#vec4_float_16]] %[[#op_ext_glsl]] FaceForward %[[#arg0]] %[[#arg1]] %[[#arg2]]
41 %spv.faceforward = call <4 x half> @llvm.spv.faceforward.v4f16(<4 x half> %a, <4 x half> %b, <4 x half> %c)
42 ret <4 x half> %spv.faceforward
43 }
44
45 define internal noundef <4 x float> @faceforward_float4(<4 x float> noundef %a, <4 x float> noundef %b, <4 x float> noundef %c) {
46 entry:
47 ; CHECK: %[[#]] = OpFunction %[[#vec4_float_32]] None %[[#]]
48 ; CHECK: %[[#arg0:]] = OpFunctionParameter %[[#vec4_float_32]]
49 ; CHECK: %[[#arg1:]] = OpFunctionParameter %[[#vec4_float_32]]
50 ; CHECK: %[[#arg2:]] = OpFunctionParameter %[[#vec4_float_32]]
51 ; CHECK: %[[#]] = OpExtInst %[[#vec4_float_32]] %[[#op_ext_glsl]] FaceForward %[[#arg0]] %[[#arg1]] %[[#arg2]]
52 %spv.faceforward = call <4 x float> @llvm.spv.faceforward.v4f32(<4 x float> %a, <4 x float> %b, <4 x float> %c)
53 ret <4 x float> %spv.faceforward
54 }
55
56 define internal noundef float @faceforward_instcombine_float(float noundef %a, float noundef %b, float noundef %c) {
57 entry:
58 ; CHECK: %[[#]] = OpFunction %[[#float_32]] None %[[#]]
59 ; CHECK: %[[#arg0:]] = OpFunctionParameter %[[#float_32]]
60 ; CHECK: %[[#arg1:]] = OpFunctionParameter %[[#float_32]]
61 ; CHECK: %[[#arg2:]] = OpFunctionParameter %[[#float_32]]
62 ; CHECK: %[[#]] = OpExtInst %[[#float_32]] %[[#op_ext_glsl]] FaceForward %[[#arg0]] %[[#arg1]] %[[#arg2]]
63 %fmul= fmul float %b, %c
64 %fcmp = fcmp olt float %fmul, 0.000000e+00
65 %fneg = fneg float %a
66 %select = select i1 %fcmp, float %a, float %fneg
67 ret float %select
68 }
69
70 define internal noundef <4 x float> @faceforward_instcombine_float4(<4 x float> noundef %a, <4 x float> noundef %b, <4 x float> noundef %c) {
71 entry:
72 ; CHECK: %[[#]] = OpFunction %[[#vec4_float_32]] None %[[#]]
73 ; CHECK: %[[#arg0:]] = OpFunctionParameter %[[#vec4_float_32]]
74 ; CHECK: %[[#arg1:]] = OpFunctionParameter %[[#vec4_float_32]]
75 ; CHECK: %[[#arg2:]] = OpFunctionParameter %[[#vec4_float_32]]
76 ; CHECK: %[[#]] = OpExtInst %[[#vec4_float_32]] %[[#op_ext_glsl]] FaceForward %[[#arg0]] %[[#arg1]] %[[#arg2]]
77 %spv.fdot = call float @llvm.spv.fdot.v4f32(<4 x float> %b, <4 x float> %c)
78 %fcmp = fcmp olt float %spv.fdot, 0.000000e+00
79 %fneg = fneg <4 x float> %a
80 %select = select i1 %fcmp, <4 x float> %fneg, <4 x float> %a
81 ret <4 x float> %select
82 }
83
84 define internal noundef float @faceforward_instcombine_float_constants(float noundef %a, float noundef %b, float noundef %c) {
85 entry:
86 ; CHECK: %[[#]] = OpFunction %[[#float_32]] None %[[#]]
87 ; CHECK: %[[#arg0:]] = OpFunctionParameter %[[#float_32]]
88 ; CHECK: %[[#arg1:]] = OpFunctionParameter %[[#float_32]]
89 ; CHECK: %[[#arg2:]] = OpFunctionParameter %[[#float_32]]
90 ; CHECK: %[[#]] = OpExtInst %[[#float_32]] %[[#op_ext_glsl]] FaceForward %[[#]] %[[#arg1]] %[[#arg2]]
91 %fmul = fmul float %b, %c
92 %fcmp = fcmp olt float %fmul, -0.000000e+00
93 %select = select i1 %fcmp, float 1.000000e+00, float -1.000000e+00
94 ret float %select
95 }
96
97 define internal noundef <4 x float> @faceforward_instcombine_float4_constants(<4 x float> noundef %a, <4 x float> noundef %b, <4 x float> noundef %c) {
98 entry:
99 ; CHECK: %[[#]] = OpFunction %[[#vec4_float_32]] None %[[#]]
100 ; CHECK: %[[#arg0:]] = OpFunctionParameter %[[#vec4_float_32]]
101 ; CHECK: %[[#arg1:]] = OpFunctionParameter %[[#vec4_float_32]]
102 ; CHECK: %[[#arg2:]] = OpFunctionParameter %[[#vec4_float_32]]
103 ; CHECK: %[[#]] = OpExtInst %[[#vec4_float_32]] %[[#op_ext_glsl]] FaceForward %[[#]] %[[#arg1]] %[[#arg2]]
104 %spv.fdot = call float @llvm.spv.fdot.v4f32(<4 x float> %b, <4 x float> %c)
105 %fcmp = fcmp olt float %spv.fdot, 0.000000e+00
106 %select = select i1 %fcmp, <4 x float> <float 1.000000e+00, float 2.000000e+00, float 3.000000e+00, float 4.000000e+00>, <4 x float> <float -1.000000e+00, float -2.000000e+00, float -3.000000e+00, float -4.000000e+00>
107 ret <4 x float> %select
108 }
109
110 define internal noundef <4 x float> @faceforward_instcombine_float4_splat(<4 x float> noundef %a, <4 x float> noundef %b, <4 x float> noundef %c) {
111 entry:
112 ; CHECK: %[[#]] = OpFunction %[[#vec4_float_32]] None %[[#]]
113 ; CHECK: %[[#arg0:]] = OpFunctionParameter %[[#vec4_float_32]]
114 ; CHECK: %[[#arg1:]] = OpFunctionParameter %[[#vec4_float_32]]
115 ; CHECK: %[[#arg2:]] = OpFunctionParameter %[[#vec4_float_32]]
116 ; CHECK: %[[#]] = OpExtInst %[[#vec4_float_32]] %[[#op_ext_glsl]] FaceForward %[[#]] %[[#arg1]] %[[#arg2]]
117 %spv.fdot = call float @llvm.spv.fdot.v4f32(<4 x float> %b, <4 x float> %c)
118 %fcmp = fcmp olt float %spv.fdot, 0.000000e+00
119 %select = select i1 %fcmp, <4 x float> splat (float 2.500000e+00), <4 x float> splat (float -2.500000e+00)
120 ret <4 x float> %select
121 }
122
123 define internal noundef <4 x float> @faceforward_instcombine_float4_false_fmul(<4 x float> noundef %a, <4 x float> noundef %b, <4 x float> noundef %c) {
124 entry:
125 ; CHECK: %[[#]] = OpFunction %[[#vec4_float_32]] None %[[#]]
126 ; CHECK: %[[#arg0:]] = OpFunctionParameter %[[#vec4_float_32]]
127 ; CHECK: %[[#arg1:]] = OpFunctionParameter %[[#vec4_float_32]]
128 ; CHECK: %[[#arg2:]] = OpFunctionParameter %[[#vec4_float_32]]
129 ; CHECK: %[[#]] = OpExtInst %[[#vec4_float_32]] %[[#op_ext_glsl]] FaceForward %[[#]] %[[#arg1]] %[[#arg2]]
130 %spv.fdot = call float @llvm.spv.fdot.v4f32(<4 x float> %b, <4 x float> %c)
131 %fcmp = fcmp olt float %spv.fdot, 0.000000e+00
132 %fneg = fmul <4 x float> %a, <float -1.000000e+00, float -1.000000e+00, float -1.000000e+00, float -1.000000e+00>
133 %select = select i1 %fcmp, <4 x float> %a, <4 x float> %fneg
134 ret <4 x float> %select
135 }
136
137 define internal noundef <4 x float> @faceforward_instcombine_float4_ogt(<4 x float> noundef %a, <4 x float> noundef %b, <4 x float> noundef %c) {
138 entry:
139 ; CHECK: %[[#]] = OpFunction %[[#vec4_float_32]] None %[[#]]
140 ; CHECK: %[[#arg0:]] = OpFunctionParameter %[[#vec4_float_32]]
141 ; CHECK: %[[#arg1:]] = OpFunctionParameter %[[#vec4_float_32]]
142 ; CHECK: %[[#arg2:]] = OpFunctionParameter %[[#vec4_float_32]]
143 ; CHECK: %[[#]] = OpExtInst %[[#vec4_float_32]] %[[#op_ext_glsl]] FaceForward %[[#]] %[[#arg1]] %[[#arg2]]
144 %spv.fdot = call float @llvm.spv.fdot.v4f32(<4 x float> %b, <4 x float> %c)
145 %fcmp = fcmp ogt float 0.000000e+00, %spv.fdot
146 %fneg = fneg <4 x float> %a
147 %select = select i1 %fcmp, <4 x float> %fneg, <4 x float> %a
148 ret <4 x float> %select
149 }
150
151 ; The other functions are the test, but a entry point is required to have a valid SPIR-V module.
152 define void @main() #1 {
153 entry:
154 ret void
155 }
156
157 declare half @llvm.spv.faceforward.f16(half, half, half)
158 declare float @llvm.spv.faceforward.f32(float, float, float)
159
160 declare <4 x half> @llvm.spv.faceforward.v4f16(<4 x half>, <4 x half>, <4 x half>)
161 declare <4 x float> @llvm.spv.faceforward.v4f32(<4 x float>, <4 x float>, <4 x float>)
162
163 attributes #1 = { convergent noinline norecurse "hlsl.numthreads"="1,1,1" "hlsl.shader"="compute" "no-trapping-math"="true" "stack-protector-buffer-size"="8" }