<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/66261>66261</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[SPIRV] SPIR-V module layout doesn't respect the spec.
</td>
</tr>
<tr>
<th>Labels</th>
<td>
backend:SPIR-V
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
Keenuts
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
Keenuts
</td>
</tr>
</table>
<pre>
The layout of a SPIR-V module is very strict (https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#_logical_layout_of_a_module).
Example:
- An OpVariable instruction cannot be present outside of the first block of a function.
As-is, the backend doesn't respect those rules, but lower IR instructions to SPIR-V in place.
This means the following LLVM IR won't build to a valid SPIR-V module:
```ll
define void @main() #1 {
entry:
%0 = alloca <2 x i32>, align 4
%1 = getelementptr <2 x i32>, ptr %0, i32 0, i32 0
%2 = alloca float, align 4
ret void
}
attributes #1 = { "hlsl.numthreads"="4,8,16" "hlsl.shader"="compute" }
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJxsVFFvozgQ_jWTl1EiGANJHnjINhtpdXu6096qr5GBSfDV2JE9bjf__gShbXpbCRljvplvvoH5dIzm7JhrKL8A0R_MLkkEIij3C52k96GeDxeN7671z57R6qtPgv6EGv_5-9uP5SMOvkuW0UR85nDFKMG0gkCbXuQSQe2ADkCHwGcTJVxXT33wzseVD2egwy0J0CFeuI1Ah-TMyXCXz-8eV70MFkgdrT-bVtvjrYSjPx318cYNtF1Btodsd1u__tLDxfJIPT3jEncO_7o86mB0M9bqooTUivEOW-2cF2wYL4EjO0GfJJqOR5HSM55MiIKN9e3TTfcpuSn0A-cuLk0EephCGt0-seuw8xwd0Fow8KhPUHofGUOyPIGbJGj9Cwf89uO-qojiX_trHF6sbnmm-9mbiAPrETNW5631L8ad8fv3xz_HNC_-RtkkY7sxj8ZnbU338Xu9NWdeq-x2WXs76PhkHOOzNx1CkQ3aOKAN0BaBVI6w_nLDsZNwfe80ApUZgtqjtta3GkE9EP5CowjU11GytubssLjD5xP-zMKWB3ZykfB72HRIZTbujSK827xnonvmk_VaPmEMLJOsWfh6f98HLRJMk4TjrFPtR60IRL2NduXSIH1g3U2DovZAVAA9bIAe8gqI3oCx1x2HN1Drh0sSnhBvjK89X3S16rZqqxdc59W2qKjcUrHo645K0hlxqymv1kVWqGbbFEVWbKpSbdR6YWrKSGXbXOVrKqlYdZo5L6uClOZq05ygyHjQxq6sfR7GkVuYGBPXVUVVvrC6YRtnA5h_WlC715mcnCDUY-iySecIRWZNlPieTIzYyUCmUYVy_z9TmO3iszlgHHerRQq2_ugUZyN9alatH4AOI9V8W16C_5dbATpMIka3mHT8FwAA__-vUHST">