llvm-project/llvm/test/CodeGen/SPIRV/transcoding/bitcast-diff-addrspace.ll
Vyacheslav Levytskyy 9a737109a0
[SPIR-V] Improve type inference, addrspacecast and dependencies between SPIR-V entities and required capability/extensions (#94626)
This PR continues https://github.com/llvm/llvm-project/pull/94467 and
contains fixes in emission of type intrinsics, constant recording and
corresponding test cases:
* type-deduce-global-dup.ll -- fix of integer constant emission on
32-bit platforms and correct type deduction for globals
* type-deduce-simple-for.ll -- fix of GEP translation (there was an
issue previously that led to incorrect translation/broken logic of
for-range implementation)

This PR also:
* fixes a cast between identical storage classes and updates the test
case to include validation run by spirv-val,
* ensures that Bitcast for pointers satisfies the requirement that the
address spaces must match and adds the corresponding test case,
* improve encode in Tablegen and decode in code of dependencies between
SPIR-V entities and required capability/extensions,
* prevent emission of identical OpTypePointer instructions.
2024-06-07 21:12:33 +02:00

45 lines
2.1 KiB
LLVM

; Check that bitcast for pointers implies that the address spaces must match.
; RUN: llc -O0 -mtriple=spirv64-unknown-unknown %s --spirv-ext=+SPV_INTEL_usm_storage_classes -o - | FileCheck %s
; TODO: %if spirv-tools %{ llc -O0 -mtriple=spirv64-unknown-unknown %s --spirv-ext=+SPV_INTEL_usm_storage_classes -o - -filetype=obj | spirv-val %}
; CHECK: Capability USMStorageClassesINTEL
; CHECK: OpExtension "SPV_INTEL_usm_storage_classes"
; CHECK-DAG: OpName %[[#Bar:]] "bar"
; CHECK-DAG: %[[#Void:]] = OpTypeVoid
; CHECK-DAG: %[[#Char:]] = OpTypeInt 8 0
; CHECK-DAG: %[[#GenPtrChar:]] = OpTypePointer Generic %[[#Char]]
; CHECK-DAG: %[[#AtDevice:]] = OpTypePointer DeviceOnlyINTEL %[[#Char]]
; CHECK-DAG: %[[#AtHost:]] = OpTypePointer HostOnlyINTEL %[[#Char]]
; CHECK-DAG: %[[#PtrVarHost:]] = OpTypePointer Function %[[#AtHost]]
; CHECK-DAG: %[[#PtrVarDevice:]] = OpTypePointer Function %[[#AtDevice]]
; CHECK: OpFunction
; CHECK: %[[#VarDevice:]] = OpVariable %[[#PtrVarDevice]] Function
; CHECK: %[[#VarHost:]] = OpVariable %[[#PtrVarHost]] Function
; CHECK: %[[#LoadedDevice:]] = OpLoad %[[#AtDevice]] %[[#VarDevice]]
; CHECK: %[[#CastedFromDevice:]] = OpPtrCastToGeneric %[[#GenPtrChar]] %[[#LoadedDevice]]
; CHECK: OpFunctionCall %[[#Void]] %[[#Bar]] %[[#CastedFromDevice]]
; CHECK: %[[#LoadedHost:]] = OpLoad %[[#AtHost]] %[[#VarHost]]
; CHECK: %[[#CastedFromHost:]] = OpPtrCastToGeneric %[[#GenPtrChar]] %[[#LoadedHost]]
; CHECK: OpFunctionCall %[[#Void]] %[[#Bar]] %[[#CastedFromHost]]
define spir_func void @foo() {
entry:
%device_var = alloca ptr addrspace(5)
%host_var = alloca ptr addrspace(6)
%p1 = load ptr addrspace(5), ptr %device_var
%p2 = addrspacecast ptr addrspace(5) %p1 to ptr addrspace(4)
call spir_func void @bar(ptr addrspace(4) %p2)
%p3 = load ptr addrspace(6), ptr %host_var
%p4 = addrspacecast ptr addrspace(6) %p3 to ptr addrspace(4)
call spir_func void @bar(ptr addrspace(4) %p4)
ret void
}
define spir_func void @bar(ptr addrspace(4) %data) {
entry:
%data.addr = alloca ptr addrspace(4)
store ptr addrspace(4) %data, ptr %data.addr
ret void
}