Skip to content

[SPIR-V] Creation of a constant struct with an array field leads to invalid SPIR-V code produced #96285

@VyacheslavLevytskyy

Description

@VyacheslavLevytskyy

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().

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions