[llvm] [SPIR-V] Avoid rescanning use lists to check for Block decoration (PR #211320)
Arseniy Obolenskiy via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 4 03:46:04 PDT 2026
aobolensk wrote:
I have made some experiment on that:
```
#!/usr/bin/env python3
# Generates an .ll module that stresses SPIRVGlobalRegistry::isResourceType
# on a struct type (%BigStruct) referenced from many distinct array types.
# Each array type requires a fresh isResourceType(%BigStruct) check when
# deciding whether to add an ArrayStride decoration, so with N array types
# the check runs N times against the same struct's type register.
import sys
num_fields = int(sys.argv[1]) if len(sys.argv) > 1 else 10
num_arrays = int(sys.argv[2]) if len(sys.argv) > 2 else 20000
field_tys = ", ".join(["i32"] * num_fields)
lines = [
'target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-n8:16:32:64-G1"',
"",
f"%BigStruct = type <{{ {field_tys} }}>",
"",
"%Holder = type <{ " + ", ".join(f"[{i + 1} x %BigStruct]" for i in range(num_arrays)) + " }>",
"",
"@pc = external hidden addrspace(13) externally_initialized global %Holder, align 1",
"",
"define void @main() #1 {",
"entry:",
" ret void",
"}",
"",
'attributes #1 = { convergent noinline norecurse optnone "hlsl.numthreads"="1,1,1" "hlsl.shader"="compute" }',
"",
]
print("\n".join(lines))
```
Usage: `python3 gen_bench.py <fields-per-struct> <num-array-types> > bench.ll`, then `llc -O0 -mtriple=spirv-vulkan-unknown bench.ll -o /dev/null`
Results:
| N (array types over shared struct) | Before | After | Speedup |
|-----------------------------------:|-------:|------:|--------:|
| 5,000 | 0.07s | 0.03s | 2.3× |
| 10,000 | 0.24s | 0.05s | 4.8× |
| 20,000 | 0.81s | 0.11s | 7.4× |
| 40,000 | 3.07s | 0.25s | 12.3× |
For sure, this situation is quite artificial (I hardly imagine such cases)
https://github.com/llvm/llvm-project/pull/211320
More information about the llvm-commits
mailing list