
Prior to this patch, when `NumElems` was 0, `OpTypeRuntimeArray` was directly generated, but it requires `Shader` capability, so it can only be generated if `Shader` env is being used. We have observed a pattern of using unbound arrays that translate into `[0 x ...]` types in OpenCL, which implies `Kernel` capability, so `OpTypeRuntimeArray` should not be used. To prevent this scenario, this patch simplifies GEP instructions where type is a 0-length array and the first index is also 0. In such scenario, we effectively drop the 0-length array and the first index. Additionally, the newly added test prior to this patch was generating a module with both `Shader` and `Kernel` capabilities at the same time, but they're incompatible. This patch also fixes that. Finally, prior to this patch, the newly added test was adding `Shader` capability to the module even with the command line flag `--avoid-spirv-capabilities=Shader`. This patch also has a fix for that.
24 lines
866 B
LLVM
24 lines
866 B
LLVM
; RUN: llc -verify-machineinstrs -O0 -mtriple=spirv-unknown-vulkan-compute %s -o - | FileCheck %s
|
|
; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv-unknown-vulkan-compute %s -o - -filetype=obj | spirv-val --target-env vulkan1.3 %}
|
|
|
|
@PrivInternal = internal addrspace(10) global i32 456
|
|
; CHECK-DAG: %[[#type:]] = OpTypeInt 32 0
|
|
; CHECK-DAG: %[[#ptrty:]] = OpTypePointer Private %[[#type]]
|
|
; CHECK-DAG: %[[#value:]] = OpConstant %[[#type]] 456
|
|
; CHECK-DAG: %[[#var:]] = OpVariable %[[#ptrty]] Private %[[#value]]
|
|
|
|
define hidden spir_func void @Foo() {
|
|
%p = addrspacecast ptr addrspace(10) @PrivInternal to ptr
|
|
%v = load i32, ptr %p, align 4
|
|
ret void
|
|
; CHECK: OpLabel
|
|
; CHECK-NEXT: OpLoad %[[#type]] %[[#var]] Aligned 4
|
|
; CHECK-Next: OpReturn
|
|
}
|
|
|
|
define void @main() #1 {
|
|
ret void
|
|
}
|
|
|
|
attributes #1 = { "hlsl.numthreads"="8,1,1" "hlsl.shader"="compute" }
|