Skip to content

kernel calling alloca in non-top block fails validation #3389

@simeonschaub

Description

@simeonschaub

Reproducer:

target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-G1"
target triple = "spir64-unknown-unknown"

define spir_kernel void @f() {
conversion:
  br label %top

top:                                              ; preds = %conversion
  %As = alloca [1 x i64], align 8
  ret void
}

gets translated to:

; SPIR-V
; Version: 1.0
; Generator: Khronos LLVM/SPIR-V Translator; 14
; Bound: 15
; Schema: 0
               OpCapability Addresses
               OpCapability Linkage
               OpCapability Kernel
               OpCapability Int64
          %1 = OpExtInstImport "OpenCL.std"
               OpMemoryModel Physical64 OpenCL
               OpEntryPoint Kernel %12 "f"
               OpSource Unknown 0
               OpName %f "f"
               OpName %conversion "conversion"
               OpName %top "top"
               OpName %As "As"
               OpDecorate %f LinkageAttributes "f" Export
               OpDecorate %As Alignment 8
      %ulong = OpTypeInt 64 0
    %ulong_1 = OpConstant %ulong 1
       %void = OpTypeVoid
          %3 = OpTypeFunction %void
%_arr_ulong_ulong_1 = OpTypeArray %ulong %ulong_1
%_ptr_Function__arr_ulong_ulong_1 = OpTypePointer Function %_arr_ulong_ulong_1
          %f = OpFunction %void None %3
 %conversion = OpLabel
               OpBranch %top
        %top = OpLabel
         %As = OpVariable %_ptr_Function__arr_ulong_ulong_1 Function
               OpReturn
               OpFunctionEnd
         %12 = OpFunction %void None %3
         %13 = OpLabel
         %14 = OpFunctionCall %void %f
               OpReturn
               OpFunctionEnd

which fails validation with:

error: line 25: All OpVariable instructions in a function must be the first instructions in the first block.
  %As = OpVariable %_ptr_Function__arr_ulong_ulong_1 Function

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