| 1 |
; This test checks that functions with `convert_` prefix are translated as |
| 2 |
; OpenCL builtins only in case they match the specification. Otherwise, we |
| 3 |
; expect such functions to be translated to SPIR-V FunctionCall. |
| 4 |
|
| 5 |
; RUN: llvm-as %s -o %t.bc |
| 6 |
; RUN: llvm-spirv %t.bc -o %t.spv |
| 7 |
; RUN: spirv-val %t.spv |
| 8 |
; RUN: llvm-spirv %t.spv -to-text -o %t.spt |
| 9 |
; RUN: FileCheck < %t.spt %s -check-prefix=CHECK-SPIRV |
| 10 |
; RUN: llvm-spirv %t.spv -r -o - | llvm-dis -o %t.rev.ll |
| 11 |
; RUN: FileCheck < %t.rev.ll %s -check-prefix=CHECK-LLVM |
| 12 |
|
| 13 |
; CHECK-SPIRV: Name [[#Func:]] "_Z18convert_float_func" |
| 14 |
; CHECK-SPIRV: Name [[#Func1:]] "_Z20convert_uint_satfunc" |
| 15 |
; CHECK-SPIRV: Name [[#Func2:]] "_Z21convert_float_rtzfunc" |
| 16 |
; CHECK-SPIRV-DAG: TypeVoid [[#VoidTy:]] |
| 17 |
; CHECK-SPIRV-DAG: TypeInt [[#CharTy:]] 8 |
| 18 |
; CHECK-SPIRV-DAG: TypeFloat [[#FloatTy:]] 32 |
| 19 |
|
| 20 |
; CHECK-SPIRV: Function [[#VoidTy]] [[#Func]] |
| 21 |
; CHECK-SPIRV: SConvert [[#CharTy]] [[#ConvertId:]] [[#]] |
| 22 |
; CHECK-SPIRV: ConvertSToF [[#FloatTy]] [[#ConvertId:]] [[#]] |
| 23 |
; CHECK-SPIRV: FunctionCall [[#VoidTy]] [[#]] [[#Func]] [[#ConvertId]] |
| 24 |
; CHECK-SPIRV: FunctionCall [[#VoidTy]] [[#]] [[#Func1]] [[#]] |
| 25 |
; CHECK-SPIRV: FunctionCall [[#VoidTy]] [[#]] [[#Func2]] [[#ConvertId]] |
| 26 |
; CHECK-SPIRV-NOT: FConvert |
| 27 |
; CHECK-SPIRV-NOT: ConvertUToF |
| 28 |
|
| 29 |
target datalayout = "e-p:32:32-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-n8:16:32:64" |
| 30 |
target triple = "spir" |
| 31 |
|
| 32 |
; Function Attrs: convergent noinline norecurse nounwind optnone |
| 33 |
define dso_local spir_func void @_Z18convert_float_func(float noundef %x) #0 { |
| 34 |
entry: |
| 35 |
%x.addr = alloca float, align 4 |
| 36 |
store float %x, ptr %x.addr, align 4 |
| 37 |
ret void |
| 38 |
} |
| 39 |
|
| 40 |
define dso_local spir_func void @_Z20convert_uint_satfunc(i32 noundef %x) #0 { |
| 41 |
entry: |
| 42 |
ret void |
| 43 |
} |
| 44 |
|
| 45 |
define dso_local spir_func void @_Z21convert_float_rtzfunc(float noundef %x) #0 { |
| 46 |
entry: |
| 47 |
ret void |
| 48 |
} |
| 49 |
|
| 50 |
; Function Attrs: convergent noinline norecurse nounwind optnone |
| 51 |
define dso_local spir_func void @convert_int_bf16(i32 noundef %x) #0 { |
| 52 |
entry: |
| 53 |
%x.addr = alloca i32, align 4 |
| 54 |
store i32 %x, ptr %x.addr, align 4 |
| 55 |
%0 = load i32, ptr %x.addr, align 4 |
| 56 |
; We don't get the convert_char_rtei back, but that's fine because they are |
| 57 |
; functionally equivalent anyway. The rounding information is lost when |
| 58 |
; translating to SPIR-V. |
| 59 |
; CHECK-LLVM: call spir_func i8 @_Z12convert_chari(i32 %[[#]]) |
| 60 |
call spir_func signext i8 @_Z16convert_char_rtei(i32 noundef %0) #1 |
| 61 |
; CHECK-LLVM: %[[Call:[a-z]+]] = sitofp i32 %[[#]] to float |
| 62 |
; CHECK-LLVM: call spir_func void @_Z18convert_float_func(float %[[Call]]) |
| 63 |
; CHECK-LLVM: call spir_func void @_Z20convert_uint_satfunc(i32 %[[#]]) |
| 64 |
; CHECK-LLVM: call spir_func void @_Z21convert_float_rtzfunc(float %[[Call]]) |
| 65 |
%call = call spir_func float @_Z13convert_floati(i32 noundef %0) #1 |
| 66 |
call spir_func void @_Z18convert_float_func(float noundef %call) #0 |
| 67 |
call spir_func void @_Z20convert_uint_satfunc(i32 noundef %0) #0 |
| 68 |
call spir_func void @_Z21convert_float_rtzfunc(float noundef %call) #0 |
| 69 |
ret void |
| 70 |
} |
| 71 |
|
| 72 |
; Function Attrs: convergent nounwind willreturn memory(none) |
| 73 |
declare spir_func signext i8 @_Z16convert_char_rtei(i32 noundef) #1 |
| 74 |
|
| 75 |
; Function Attrs: convergent nounwind willreturn memory(none) |
| 76 |
declare spir_func float @_Z13convert_floati(i32 noundef) #1 |
| 77 |
|
| 78 |
attributes #0 = { convergent nounwind } |
| 79 |
attributes #1 = { convergent nounwind willreturn memory(none) } |
| 80 |
|
| 81 |
!opencl.ocl.version = !{!0} |
| 82 |
!opencl.spir.version = !{!0} |
| 83 |
|
| 84 |
!0 = !{i32 3, i32 0} |