| 1 |
; Check support of OpPtrDiff instruction that was added in SPIR-V 1.4 |
| 2 |
|
| 3 |
; RUN: llvm-as %s -o %t.bc |
| 4 |
; RUN: not llvm-spirv --spirv-max-version=1.3 %t.bc 2>&1 | FileCheck --check-prefix=CHECK-ERROR %s |
| 5 |
|
| 6 |
; RUN: llvm-spirv %t.bc -o %t.spv |
| 7 |
; RUN: llvm-spirv %t.spv -to-text -o %t.spt |
| 8 |
; RUN: FileCheck < %t.spt %s --check-prefix=CHECK-SPIRV |
| 9 |
; RUN: spirv-val %t.spv |
| 10 |
|
| 11 |
; RUN: llvm-spirv -r -emit-opaque-pointers %t.spv -o %t.rev.bc |
| 12 |
; RUN: llvm-dis %t.rev.bc |
| 13 |
; RUN: FileCheck < %t.rev.ll %s --check-prefix=CHECK-LLVM |
| 14 |
|
| 15 |
; CHECK-ERROR: RequiresVersion: Cannot fulfill SPIR-V version restriction: |
| 16 |
; CHECK-ERROR-NEXT: SPIR-V version was restricted to at most 1.3 (66304) but a construct from the input requires SPIR-V version 1.4 (66560) or above |
| 17 |
|
| 18 |
; SPIR-V 1.4 |
| 19 |
; CHECK-SPIRV: 66560 |
| 20 |
; CHECK-SPIRV: TypeInt [[#TypeInt:]] 32 0 |
| 21 |
; CHECK-SPIRV: TypeFloat [[#TypeFloat:]] 32 |
| 22 |
; CHECK-SPIRV: TypePointer [[#TypePointer:]] [[#]] [[#TypeFloat]] |
| 23 |
|
| 24 |
; CHECK-SPIRV: Variable [[#TypePointer]] [[#Var:]] |
| 25 |
; CHECK-SPIRV: PtrDiff [[#TypeInt]] [[#]] [[#Var]] [[#Var]] |
| 26 |
|
| 27 |
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" |
| 28 |
target triple = "spir64-unknown-unknown" |
| 29 |
|
| 30 |
; Function Attrs: nounwind |
| 31 |
define spir_kernel void @test(float %a) local_unnamed_addr #0 { |
| 32 |
entry: |
| 33 |
%0 = alloca float, align 4 |
| 34 |
store float %a, ptr %0, align 4 |
| 35 |
; CHECK-LLVM: %[[#Arg1:]] = ptrtoint ptr %[[#]] to i64 |
| 36 |
; CHECK-LLVM: %[[#Arg2:]] = ptrtoint ptr %[[#]] to i64 |
| 37 |
; CHECK-LLVM: %[[#Sub:]] = sub i64 %[[#Arg1]], %[[#Arg2]] |
| 38 |
; CHECK-LLVM: sdiv exact i64 %[[#Sub]], ptrtoint (ptr getelementptr (float, ptr null, i32 1) to i64) |
| 39 |
%1 = call spir_func noundef i32 @_Z15__spirv_PtrDiff(ptr %0, ptr %0) |
| 40 |
ret void |
| 41 |
} |
| 42 |
|
| 43 |
declare spir_func noundef i32 @_Z15__spirv_PtrDiff(ptr, ptr) |
| 44 |
|
| 45 |
attributes #0 = { convergent nounwind writeonly } |
| 46 |
|
| 47 |
!llvm.module.flags = !{!0} |
| 48 |
!opencl.ocl.version = !{!1} |
| 49 |
!opencl.spir.version = !{!1} |
| 50 |
|
| 51 |
!0 = !{i32 1, !"wchar_size", i32 4} |
| 52 |
!1 = !{i32 2, i32 0} |