Issue 151344
Summary SPIR-V: Verification errors with struct-returning IR
Labels new issue
Assignees
Reporter maleadt
    The following two reproducers fail to compile with `llc` because of IR verification errors during compilation, presumably caused by internal SPIR-V passes. Both files compile fine when using the SPIRV-LLVM-Translator.

---

```llvm
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 = "spirv64-unknown-unknown-unknown"

define fastcc { i1, i64 } @foobar(i1 %cond, { i1, i64 } %a, { i1, i64 } %b) {
top:
  %val = select i1 %cond, { i1, i64 } %a, { i1, i64 } %b
  ret { i1, i64 } %val
}
```

Using the translator:

```
❯ llvm-as reduced1.ll -o - | llvm-spirv -o - | spirv-dis
; SPIR-V
; Version: 1.0
; Generator: Khronos LLVM/SPIR-V Translator; 14
; Bound: 12
; Schema: 0
               OpCapability Addresses
               OpCapability Linkage
               OpCapability Kernel
               OpCapability Int64
          %1 = OpExtInstImport "OpenCL.std"
               OpMemoryModel Physical64 OpenCL
               OpSource Unknown 0
               OpName %foobar "foobar"
               OpName %cond "cond"
               OpName %a "a"
               OpName %b "b"
               OpName %top "top"
               OpName %val "val"
               OpDecorate %foobar LinkageAttributes "foobar" Export
      %ulong = OpTypeInt 64 0
       %bool = OpTypeBool
  %_struct_2 = OpTypeStruct %bool %ulong
          %5 = OpTypeFunction %_struct_2 %bool %_struct_2 %_struct_2
     %foobar = OpFunction %_struct_2 None %5
       %cond = OpFunctionParameter %bool
          %a = OpFunctionParameter %_struct_2
          %b = OpFunctionParameter %_struct_2
        %top = OpLabel
        %val = OpSelect %_struct_2 %cond %a %b
               OpReturnValue %val
               OpFunctionEnd
```

Using the LLVM back-end:

```
❯ llc reduced1.ll                                   
Select values must have same type as select instruction!
  %val = select i1 %cond, i32 %a, i32 %b
Function return type does not match operand type of return inst!
  ret { i1, i64 } %val
 i32in function foobar
LLVM ERROR: Broken function found, compilation aborted!
```

---

```llvm
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 = "spirv64-unknown-unknown-unknown"

define fastcc { i1, i64 } @foobar(i1 %cond, { i1, i64 } %input) {
top:
  br i1 %cond, label %ret, label %L59.1

ret:
  %val = phi { i1, i64 } [ zeroinitializer, %L59.1 ], [ %input, %top ]
  ret { i1, i64 } %val

L59.1:
  br label %ret
}
```

```
❯ llvm-as reduced2.ll -o - | llvm-spirv -o - | spirv-dis                            
; SPIR-V
; Version: 1.0
; Generator: Khronos LLVM/SPIR-V Translator; 14
; Bound: 14
; Schema: 0
               OpCapability Addresses
               OpCapability Linkage
               OpCapability Kernel
               OpCapability Int64
          %1 = OpExtInstImport "OpenCL.std"
               OpMemoryModel Physical64 OpenCL
               OpSource Unknown 0
               OpName %foobar "foobar"
               OpName %cond "cond"
               OpName %input "input"
               OpName %top "top"
               OpName %ret "ret"
               OpName %L59_1 "L59.1"
               OpName %val "val"
               OpDecorate %foobar LinkageAttributes "foobar" Export
      %ulong = OpTypeInt 64 0
       %bool = OpTypeBool
  %_struct_2 = OpTypeStruct %bool %ulong
          %5 = OpTypeFunction %_struct_2 %bool %_struct_2
         %12 = OpConstantNull %_struct_2
     %foobar = OpFunction %_struct_2 None %5
       %cond = OpFunctionParameter %bool
      %input = OpFunctionParameter %_struct_2
        %top = OpLabel
               OpBranchConditional %cond %ret %L59_1
        %ret = OpLabel
        %val = OpPhi %_struct_2 %12 %L59_1 %input %top
               OpReturnValue %val
      %L59_1 = OpLabel
               OpBranch %ret
               OpFunctionEnd
```

```
❯ llc reduced2.ll 
PHI node operands are not the same type as the result!
  %val = phi { i1, i64 } [ %1, %L59.1 ], [ %input, %top ]
Function return type does not match operand type of return inst!
  ret { i1, i64 } %val
 i32in function foobar
```

---

Reproduced on latest master.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to