<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/81753>81753</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [SPIRV] OpExecutionMode Entry Point <id> is not the Entry Point operand of an OpEntryPoint
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          VyacheslavLevytskyy
      </td>
    </tr>
</table>

<pre>
    SPIRV-V Backend generates unnecessary OpExecutionMode records, putting into the <id>'s which are not the Entry Point operands of an OpEntryPoint and thus violating specification requirements (https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#OpExecutionMode).

Example of the code that causes one more, unnecessary OpExecutionMode record in addition to a required one is the following:

```
@GV = linkonce_odr addrspace(1) global [3 x i32] zeroinitializer, align 4

define spir_kernel void @k() {
entry:
  %call = call spir_func i32 @square(i32 2)
  ret void
}

define linkonce_odr dso_local spir_func i32 @square(i32 %in) {
entry:
  %in.addr = alloca i32, align 4
  store i32 %in, i32* %in.addr, align 4
  %0 = load i32, i32* %in.addr, align 4
  %1 = load i32, i32* %in.addr, align 4
  %mul = mul nsw i32 %0, %1
  ret i32 %mul
}
```

In the output there will be two OpExecutionMode instructions with just one OpEntryPoint:

```
...
        OpEntryPoint Kernel %14 "k" %12
        OpExecutionMode %14 ContractionOff
        OpExecutionMode %17 ContractionOff
...
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJycVU1v4zYQ_TXUZRBBoqSVfdAhieNi0Ra7aAFfA5ocSVzTpJYfdry_viBlp4432BQNAsnEcN68N6TeMOfkoBE70jyQZpWx4Edju82J8RGdYoc_8HDybnc6ZVsjTt3fXz__tbnbwAPjO9QCBtRomUcHQWvk6ByzJ_gyPb0gD14a_acRCBa5scIR-ghT8F7qAaT2BvyIQKpHKUj1RGjr4DhKPgKzC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