| 1 |
; RUN: llc -O0 -mtriple=spirv-unknown-vulkan %s -o - | FileCheck %s |
| 2 |
; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv-unknown-vulkan %s -o - -filetype=obj | spirv-val %} |
| 3 |
|
| 4 |
; Make sure SPIRV operation function calls for saturate 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 |
; CHECK-DAG: %[[#float_64:]] = OpTypeFloat 64 |
| 12 |
; CHECK-DAG: %[[#vec4_float_64:]] = OpTypeVector %[[#float_64]] 4 |
| 13 |
; CHECK-DAG: %[[#zero_float_16:]] = OpConstant %[[#float_16]] 0 |
| 14 |
; CHECK-DAG: %[[#vec4_zero_float_16:]] = OpConstantComposite %[[#vec4_float_16]] %[[#zero_float_16]] %[[#zero_float_16]] %[[#zero_float_16]] |
| 15 |
; CHECK-DAG: %[[#one_float_16:]] = OpConstant %[[#float_16]] 15360 |
| 16 |
; CHECK-DAG: %[[#vec4_one_float_16:]] = OpConstantComposite %[[#vec4_float_16]] %[[#one_float_16]] %[[#one_float_16]] %[[#one_float_16]] |
| 17 |
; CHECK-DAG: %[[#zero_float_32:]] = OpConstant %[[#float_32]] 0 |
| 18 |
; CHECK-DAG: %[[#vec4_zero_float_32:]] = OpConstantComposite %[[#vec4_float_32]] %[[#zero_float_32]] %[[#zero_float_32]] %[[#zero_float_32]] |
| 19 |
; CHECK-DAG: %[[#one_float_32:]] = OpConstant %[[#float_32]] 1 |
| 20 |
; CHECK-DAG: %[[#vec4_one_float_32:]] = OpConstantComposite %[[#vec4_float_32]] %[[#one_float_32]] %[[#one_float_32]] %[[#one_float_32]] |
| 21 |
|
| 22 |
; CHECK-DAG: %[[#zero_float_64:]] = OpConstant %[[#float_64]] 0 |
| 23 |
; CHECK-DAG: %[[#vec4_zero_float_64:]] = OpConstantComposite %[[#vec4_float_64]] %[[#zero_float_64]] %[[#zero_float_64]] %[[#zero_float_64]] |
| 24 |
; CHECK-DAG: %[[#one_float_64:]] = OpConstant %[[#float_64]] 1 |
| 25 |
; CHECK-DAG: %[[#vec4_one_float_64:]] = OpConstantComposite %[[#vec4_float_64]] %[[#one_float_64]] %[[#one_float_64]] %[[#one_float_64]] |
| 26 |
|
| 27 |
define noundef half @saturate_half(half noundef %a) { |
| 28 |
entry: |
| 29 |
; CHECK: %[[#]] = OpFunction %[[#float_16]] None %[[#]] |
| 30 |
; CHECK: %[[#arg0:]] = OpFunctionParameter %[[#float_16]] |
| 31 |
; CHECK: %[[#]] = OpExtInst %[[#float_16]] %[[#op_ext_glsl]] FClamp %[[#arg0]] %[[#zero_float_16]] %[[#one_float_16]] |
| 32 |
%hlsl.saturate = call half @llvm.spv.saturate.f16(half %a) |
| 33 |
ret half %hlsl.saturate |
| 34 |
} |
| 35 |
|
| 36 |
define noundef float @saturate_float(float noundef %a) { |
| 37 |
entry: |
| 38 |
; CHECK: %[[#]] = OpFunction %[[#float_32]] None %[[#]] |
| 39 |
; CHECK: %[[#arg0:]] = OpFunctionParameter %[[#float_32]] |
| 40 |
; CHECK: %[[#]] = OpExtInst %[[#float_32]] %[[#op_ext_glsl]] FClamp %[[#arg0]] %[[#zero_float_32]] %[[#one_float_32]] |
| 41 |
%hlsl.saturate = call float @llvm.spv.saturate.f32(float %a) |
| 42 |
ret float %hlsl.saturate |
| 43 |
} |
| 44 |
|
| 45 |
define noundef double @saturate_double(double noundef %a) { |
| 46 |
entry: |
| 47 |
; CHECK: %[[#]] = OpFunction %[[#float_64]] None %[[#]] |
| 48 |
; CHECK: %[[#arg0:]] = OpFunctionParameter %[[#float_64]] |
| 49 |
; CHECK: %[[#]] = OpExtInst %[[#float_64]] %[[#op_ext_glsl]] FClamp %[[#arg0]] %[[#zero_float_64]] %[[#one_float_64]] |
| 50 |
%hlsl.saturate = call double @llvm.spv.saturate.f64(double %a) |
| 51 |
ret double %hlsl.saturate |
| 52 |
} |
| 53 |
|
| 54 |
define noundef <4 x half> @saturate_half4(<4 x half> noundef %a) { |
| 55 |
entry: |
| 56 |
; CHECK: %[[#]] = OpFunction %[[#vec4_float_16]] None %[[#]] |
| 57 |
; CHECK: %[[#arg0:]] = OpFunctionParameter %[[#vec4_float_16]] |
| 58 |
; CHECK: %[[#]] = OpExtInst %[[#vec4_float_16]] %[[#op_ext_glsl]] FClamp %[[#arg0]] %[[#vec4_zero_float_16]] %[[#vec4_one_float_16]] |
| 59 |
%hlsl.saturate = call <4 x half> @llvm.spv.saturate.v4f16(<4 x half> %a) |
| 60 |
ret <4 x half> %hlsl.saturate |
| 61 |
} |
| 62 |
|
| 63 |
define noundef <4 x float> @saturate_float4(<4 x float> noundef %a) { |
| 64 |
entry: |
| 65 |
; CHECK: %[[#]] = OpFunction %[[#vec4_float_32]] None %[[#]] |
| 66 |
; CHECK: %[[#arg0:]] = OpFunctionParameter %[[#vec4_float_32]] |
| 67 |
; CHECK: %[[#]] = OpExtInst %[[#vec4_float_32]] %[[#op_ext_glsl]] FClamp %[[#arg0]] %[[#vec4_zero_float_32]] %[[#vec4_one_float_32]] |
| 68 |
%hlsl.saturate = call <4 x float> @llvm.spv.saturate.v4f32(<4 x float> %a) |
| 69 |
ret <4 x float> %hlsl.saturate |
| 70 |
} |
| 71 |
|
| 72 |
define noundef <4 x double> @saturate_double4(<4 x double> noundef %a) { |
| 73 |
entry: |
| 74 |
; CHECK: %[[#]] = OpFunction %[[#vec4_float_64]] None %[[#]] |
| 75 |
; CHECK: %[[#arg0:]] = OpFunctionParameter %[[#vec4_float_64]] |
| 76 |
; CHECK: %[[#]] = OpExtInst %[[#vec4_float_64]] %[[#op_ext_glsl]] FClamp %[[#arg0]] %[[#vec4_zero_float_64]] %[[#vec4_one_float_64]] |
| 77 |
%hlsl.saturate = call <4 x double> @llvm.spv.saturate.v4f64(<4 x double> %a) |
| 78 |
ret <4 x double> %hlsl.saturate |
| 79 |
} |
| 80 |
|
| 81 |
declare <4 x half> @llvm.spv.saturate.v4f16(<4 x half>) |
| 82 |
declare <4 x float> @llvm.spv.saturate.v4f32(<4 x float>) |
| 83 |
declare <4 x double> @llvm.spv.saturate.v4f64(<4 x double>) |