<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/96285>96285</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[SPIR-V] Creation of a constant struct with an array field leads to invalid SPIR-V code produced
</td>
</tr>
<tr>
<th>Labels</th>
<td>
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
VyacheslavLevytskyy
</td>
</tr>
</table>
<pre>
Consider the following code snippet
```
%struct_array_16i32 = type { [16 x i32] }
@G = private unnamed_addr addrspace(1) constant %struct_array_16i32 { [16 x i32] [i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15] }, align 4
define spir_kernel void @test() {
ret void
}
```
Here creation of a constant struct with an array field leads to invalid SPIR-V code produced:
```
%24 = OpConstantComposite %_arr_uint_uint_16 %uint_0 %uint_1 %uint_2 %uint_3 %uint_4 %uint_5 %uint_6 %uint_7 %uint_8 %uint_9 %uint_10 %uint_11 %uint_12 %uint_13 %uint_14 %uint_15
%25 = OpSpecConstantOp %_arr_uint_uint_16 Bitcast %24
%26 = OpConstantComposite %struct_array_16i32 %25
```
The issue is insertion of an unneeded OpSpecConstantOp instruction between OpConstantComposite instructions. In this particular case this is not only unneeded but plainly incorrect, being an attempt to apply a bitcast to an aggregate type. This would fail later on SPIR-V to LLVM IR translation in CastInst::castIsValid().
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy0VV2P4jYU_TXm5WpR7HyQPORhYESLNNVWu6t5RU58AXeNHdk3TPn3lROSTNvpvFVC5mAu5-Se-4EMQZ8tYs3yLcufV7Kni_P16122FwxG3l7wdqfw835fNU7d652zQSv0QBeEkzPGvWl7htYphGB11yGx5JklT4-zSB6v8aPIA_m-paP0Xt6PvNCpAJY-A907BLbZAsu3vIA_QaeC5c_ANs9_48uSX4b4zuubJITeWnl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