Skip to content

Correct OpSpecConstantOp generation (CTS basic/progvar_prog_scope_init) #185

@iliya-diyachkov

Description

@iliya-diyachkov

Compiling OpenCL_CTS_2021/basic/progvar_prog_scope_init/OCL_asm8433e5f712585356_before_spirv_backend.ll which has this fragment

a_var = addrspace(1) global [2 x <2 x i8>] [<2 x i8> <i8 1, i8 1>, <2 x i8> <i8 1, i8 1>], align 2
@p_var = addrspace(1) global <2 x i8> addrspace(1)* bitcast (i8 addrspace(1)* getelementptr (i8, i8 addrspace(1)* getelementptr inbounds ([2 x <2 x i8>], [2 x <2 x i8>] addrspace(1)* @a_var, i32 0, i32 0, i32 0), i64 2) to <2 x i8> addrspace(1)*), align 8

I get following output:

        %23 = OpVariable %9 CrossWorkgroup %31
        %24 = OpVariable %10 CrossWorkgroup %17
        %25 = OpVariable %8 CrossWorkgroup %16
        %26 = OpVariable %8 CrossWorkgroup %29
        %30 = OpConstant %2 0 
        %29 = OpConstantComposite %3 %30 %30
        %31 = OpSpecConstantOp %10 70 %24 %18 %19
        %35 = OpConstant %2 0 
        %34 = OpConstantComposite %3 %35 %35
        %36 = OpSpecConstantOp %10 70 %24 %18 %19
        %41 = OpConstant %2 0 
        %40 = OpConstantComposite %3 %41 %41
        %42 = OpSpecConstantOp %10 70 %24 %18 %19
        %63 = OpConstant %2 0 
        %62 = OpConstantComposite %3 %63 %63
        %64 = OpSpecConstantOp %10 70 %24 %18 %19

The SPIRV translator gives this output:

          %8 = OpConstantComposite %v2uchar %uchar_1 %uchar_1
...
         %13 = OpConstantComposite %_arr_v2uchar_ulong_2 %8 %8
      %a_var = OpVariable %_ptr_CrossWorkgroup__arr_v2uchar_ulong_2 CrossWorkgroup %13
         %19 = OpSpecConstantOp %_ptr_CrossWorkgroup_uchar PtrAccessChain %a_var %uint_0 %uint_0 %ulong_2
         %20 = OpSpecConstantOp %_ptr_CrossWorkgroup_v2uchar Bitcast %19
      %p_var = OpVariable %_ptr_CrossWorkgroup__ptr_CrossWorkgroup_v2uchar CrossWorkgroup %20

So we need to correct OpSpecConstantOp generation and avoid the instruction duplication.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions