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

    <tr>
        <th>Summary</th>
        <td>
            DeadArgumentElimination creates invalid code with musttail calls
        </td>
    </tr>

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

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

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

<pre>
    Similar to one with structs #107569, but it appears to happen even without structs:

```
define i64 @A() {
entry:
 %v2660 = musttail call i64 @B()
  ret i64 %v2660
}

define internal i64 @B() {
entry:
  ret i64 0
}

define internal i64 @C() {
entry:
 %v30543 = musttail call i64 @B()
  ret i64 %v30543
}
```

```
 opt -S -passes=deadargelim reduced.ll
cannot guarantee tail call due to mismatched return types
  %v30543 = musttail call i64 @B()
LLVM ERROR: Broken module found, compilation aborted!

opt -version
Ubuntu LLVM version 19.1.1
 Optimized build.
  Default target: x86_64-pc-linux-gnu
  Host CPU: znver3

```

Using llvm 19.1.1, but also appears to still happen in whatever compiler explorer has for trunk (21.0.0git)

https://godbolt.org/z/f6Pb88Kfc

</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJyUVEuP2zYQ_jX0ZWCBpJ4-6KBdxyjQFAk2SK8FJY4lJhQpkEPv49cXkr3ddFsUDUDAFjXffA9xqGI0o0NsWXnHyuNOJZp8aPW3R0XRu13v9XP7xczGqgDkwTuER0MTRAppoAhM5oLXZXVg8h76RGAI1LKgCnGtn9b_DvCCbsP5RK9QlneMb6vit8U7jWfjEExVACt4x2TD5AFYfcd4h47C8xUFTJYXWVUcWH6EOUUiZSwMytpX7N0VuxZDQLpu31AraX28sr8yOsLg1Hv4v1D_1e3_tLn_Twc5L4v85y1ssDfyH-J79wh-Idh_gf2iYsTI8qNGpVUY0ZoZAuo0oM6sZbwblHOeYEwqKEeI8KZGJ1w_5WzirGiYUK9iUnBAzwvGTd1Pmfn48fff4MPDw6cHlndwF_x3dDB7nSzC2Sen16M0-HkxVpHxDlTvA6FmUlwtbq4uGKLxjvHua58cJdja3nZBHDKRreXwaSEzmxfU0CdjdbbpPeJZJUtAaxa0ynhqqj-qYr8Me2tcetqPLm2Vv_hIcP_561rz4i4Y8n_GvGqIxo1g7WV-pb6Ng7LR_zgQkYy1r2NhHDxOivCC4WYYA-DTYn3AAJOKcPYBKCT3HZhspMh4xkdD1xwZ7yaiZRskeWLyNHrde0uZDyOTpxcmT-fqc980v54HxrudbnN9yA9qh62o80MuCtGUu6lVlZRCNHUhhDjXQha6Qa2Kipc9z7EedqaVXJZcCiFlcSjKjB94XQ-qqMsDlueyYQXHWRmbrQGs9DsTY8JWyKoR9c6qHm3crhgpHT7C9pZJud44oV1B-z6NkRXcmkjxrQ0ZstgeUekujGlGRx-smY27noshoCKMYNxFWaNh8Pp2O_3tBMZdCrZ9F5WhKfXZ4GcmTyvd7We_BP8NB2LytImMTJ5uLi6t_DMAAP__3Y2UiQ">