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

    <tr>
        <th>Summary</th>
        <td>
            Opt Crash "Invalid user of intrinsic instruction"
        </td>
    </tr>

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

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

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

<pre>
    Hi, when I optimize the following program

```
declare ptr @llvm.call.preallocated.setup(i32)
declare ptr @llvm.call.preallocated.arg(token, i32)

define internal i32 @f(ptr %m) {
  ret i32 0
}

define internal x86_thiscallcc i32 @g(ptr %m) {
  ret i32 0
}

define internal coldcc i32 @h(ptr %m) {
  ret i32 0
}

define internal i32 @j(ptr %m) {
  ret i32 1
}

define internal i32 @inalloca(ptr inalloca(i32) %p) {
  ret i32 0
}

define i32 @inalloca2_caller(ptr inalloca(i32) %p) {
 %rv = musttail call i32 @inalloca2(ptr inalloca(i32) %p)
  ret i32 %rv
}
define internal i32 @inalloca2(ptr inalloca(i32) %p) {
  ret i32 0
}

define internal i32 @preallocated(ptr preallocated(i32) %p) {
  ret i32 2
}

define void @call_things() {
  %m = alloca i32
  call i32 @f(ptr %m)
  call x86_thiscallcc i32 @g(ptr %m)
 call coldcc i32 @h(ptr %m)
  %args = alloca inalloca i32
  call i32 @inalloca(ptr inalloca(i32) %args)
  %c = call token @llvm.call.preallocated.setup(i32 1)
  %N = call ptr @llvm.call.preallocated.arg(token %c, i32 0) preallocated(i32)
  call i32 @preallocated(ptr preallocated(i32) %N) ["preallocated"(token %c)]
  ret void
}

@llvm.used = appending global [1 x ptr] [
   ptr @j
], section "llvm.metadata"
```

with command

```bash
opt -O3 a.ll -mtriple=x86_64-unknown-linux-gnu -o a-opt.ll
```

I got the following error message

```
Invalid user of intrinsic instruction!
  %c = call token @llvm.call.preallocated.setup(i32 1)
Intrinsic called with incompatible signature
  %c = call token @llvm.call.preallocated.setup(i32 1)
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.      Program arguments: opt -O3 a.ll -mtriple=x86_64-unknown-linux-gnu -o a-opt.ll
...
[1]    2307030 segmentation fault  opt -O3 a.ll -mtriple=x86_64-unknown-linux-gnu -o a-opt.ll
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJysVk1v2zgQ_TX0ZWCBoixbPujQxA02wKIt0NOeCooaS0woUuBHku6vX5BSGtsbOElrw5AgiXzvcebNkNw52WnEmpRXpNwtePC9sfU_XHfXPeqfgetFY9qf9V-SsGt47FHDLZjRy0H-i-B7hL1RyjxK3cFoTWf5QOiO0E_zdU3nf3psUShuEUZvgayoUg9DJrhS2WiRK2UE99hmDn0YCatkwQjbfmQmtx1hlTf3qKPcQ4BnmL3UCFJ7tJqrOCLC7QmrEjIrB8K2QDZX03gAiz6NmldANrtzeE_V-ofvpYvShHiG7y4FL4xqX2D7S8HOeHdv4-UfwZN6yswMe_A4JSYSjb8l_Bif_YjhRvsBHsJK-wCk2MEQnPdcKogY_0N-C_JUdsI9kf5GdN7k-OO8HpbITHby6m1Cdo7wwcg2EsUQRvvrzhFWnSBFV6WIT8SpOOdPh6E_KcWjIe-qrnlGmnC2Xg6Ecdu5I236vMj3ODtiHrOIRJFwUot6XwuE_BjlywvKu5thYp87ItAo8FUDvLbUj5jnS7qXV4Sx4zHsRMiWlLtDh0UDvWqw59UFh-2UoHFE3cbdplOm4SrS5fAUQ0HKXSKfcZ-jczcjlbsYAIfCSxN1sAQ8oOct9zxqfG3Hmq6P0vcgzDBw3b66vTXc9dMrM3pYfi2AZ0rBcvBWjgpJsYveXa-WQd9r86iXSurwtOx0gKUBvjSjz5Q6o-AWOuNP9lu01lgY0Dne4Zld91Y_cCVbCA4tmH3sD1ZqJwVI7bwNKSKE5Ze06u0vjtSbW0ghlFqYYeReNgohnjy4DxYvyfv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