Issue 185409
Summary [SPIRV] Backend generates invalid SPIRV code with function pointers used in comparison
Labels bug, backend:SPIR-V
Assignees
Reporter jmmartinez
    ## Overview

LLVM-IR coming from `llvm/test/CodeGen/SPIRV/extensions/SPV_INTEL_function_pointers/fp_cmp.ll`.

With `spirv-val` (with this patch applied https://github.com/KhronosGroup/SPIRV-Tools/pull/6232), `spirv-val` fails with error:

```bash
error: line 32: The types of Operand 1 and Operand 2 must match
%15 = OpPtrEqual %bool %12 %arg
```

## Steps to reproduce

```
llc -mtriple spirv64-- -O0 --spirv-ext=+SPV_INTEL_function_pointers %s -o - | spirv-val
```

```llvm
define spir_func void @f1() addrspace(9) {
entry:
  ret void
}

define spir_func i1 @foo(ptr addrspace(9) %arg) addrspace(9) {
entry:
  %a = icmp eq ptr addrspace(9) @f1, %arg
  ret i1 %a
}
```

This generates the following SPIRV code:

```spirv
 OpCapability Kernel
        OpCapability Addresses
        OpCapability Linkage
        OpCapability FunctionPointersINTEL
        OpCapability Int8
        OpExtension "SPV_INTEL_function_pointers"
        %1 = OpExtInstImport "OpenCL.std"
        OpMemoryModel Physical64 OpenCL
 OpSource OpenCL_CPP 100000
        OpName %11 "f1"
        OpName %2 "entry"
        OpName %13 "arg"
        OpName %14 "foo"
 OpName %3 "entry"
        OpDecorate %11 LinkageAttributes "f1" Export
 OpDecorate %14 LinkageAttributes "foo" Export
        %4 = OpTypeVoid
        %5 = OpTypeFunction %4
        %6 = OpTypeInt 8 0
 %7 = OpTypePointer CodeSectionINTEL %6
        %8 = OpTypeBool
        %9 = OpTypeFunction %8 %7
        %10 = OpTypePointer CodeSectionINTEL %5
 %12 = OpConstantFunctionPointerINTEL %10 %11
        %11 = OpFunction %4 None %5             ; -- Begin function f1
        %2 = OpLabel
 OpReturn
        OpFunctionEnd
                                        ; -- End function
        %14 = OpFunction %8 None %9             ; -- Begin function foo
        %13 = OpFunctionParameter %7
        %3 = OpLabel
 %15 = OpPtrEqual %8 %12 %13
        OpReturnValue %15
 OpFunctionEnd
```

These are the relevant opcodes (notice the pointer type mismatch between the function pointer and the function argument):

```
 %4 = OpTypeVoid
        %5 = OpTypeFunction %4
        %6 = OpTypeInt 8 0
        %7 = OpTypePointer CodeSectionINTEL %6 ; addrspace(CodeSectionINTEL) i8*
        %10 = OpTypePointer CodeSectionINTEL %5 ; addrspace(CodeSectionINTEL) void(*)()
        %12 = OpConstantFunctionPointerINTEL %10 %11
        %11 = OpFunction %4 None %5
 %13 = OpFunctionParameter %7
        %15 = OpPtrEqual %8 %12 %13
```
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to