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

    <tr>
        <th>Summary</th>
        <td>
            WebAssembly backend does not generate return_call for musttail calls with multiple return values
        </td>
    </tr>

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

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

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

<pre>
    Given x.ll

```ll
%t = type { i64, i64 }

declare %t @f()

define private %t @g() {
entry:
  %0 = musttail call %t @f()
  ret %t %0
}
```

the WebAssembly backend does not generate a `return_call` but a plain `call`, thus growing the stack.

I'm using LLVM 20.1.2 with the invocation `llc-20 -mattr=+multivalue,+tail-call -mtriple=wasm64-unknown-unknown --filetype=asm -o x.wat x.ll`, but the same issue arises on `wasm32` and without `multivalue` enabled.

When changing the type to `%t = type i64`, `return_call` is used as expected.

The (faulty) generated WebAssembly for the module above is:

```wat
        .file   "x.ll"
        .globaltype     __stack_pointer, i64
        .functype       f (i64) -> ()
        .functype       .Lg (i64) -> ()
        .section        .text..Lg,"",@
        .type   .Lg,@function                   # -- Begin function g
.Lg:                                    # @g
        .functype       .Lg (i64) -> ()
        .local          i64, i64
# %bb.0: # %entry
        global.get      __stack_pointer
        i64.const       16
        i64.sub 
        local.tee       1
        global.set      __stack_pointer
        local.get       1
        call    f
        local.get       1
        i64.load        0
        local.set       2
        local.get       0
        local.get       1
        i64.load        8
        i64.store       8
        local.get       0
        local.get       2
        i64.store       0
        local.get       1
        i64.const       16
        i64.add 
        global.set      __stack_pointer
                                        # fallthrough-return
        end_function
                                        # -- End function
        .section        .custom_section.target_features,"",@
        .int8   10
        .int8   43
        .int8   11
        .ascii  "bulk-memory"
        .int8   43
        .int8   15
        .ascii  "bulk-memory-opt"
        .int8   43
        .int8   22
        .ascii  "call-indirect-overlong"
        .int8   43
        .int8   10
        .ascii  "multivalue"
        .int8   43
        .int8   15
        .ascii  "mutable-globals"
        .int8   43
        .int8   19
        .ascii  "nontrapping-fptoint"
        .int8   43
        .int8   15
        .ascii  "reference-types"
        .int8   43
        .int8   8
        .ascii  "sign-ext"
        .int8   43
        .int8   9
        .ascii  "tail-call"
        .int8   43
        .int8   8
        .ascii  "memory64"
        .section        .text..Lg,"",@
```
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJycVlFv4joT_TXmZZTIOEDJAw_tsv30Sb1vV3cfkZNMgm8dO7In0P77K9uh0IXddosihdgzZ86Mj-2R3qvOIG7Y8oEttzM50t66TS17pT3Jwc8q27xu_qcOaOAl15rx-_CseHrSgFgSsGIL9DogsLsHUKsFE9_CC9jdNvk0WGvpEJL1grdMrJkoT5OtMgiDUwdJZ5su2QRMxu_RkHtlRbCHYMJj0H70RFJpqKXWN9ABHNI0LpY8xEuUTjkkBrRH-IHVvffYV_oVKlk_o2mgsejBWIIODbpATgJbcYc0OrMLMdmKQzUSSBi0VCbMTsOhBrQfPXTOHpXpIATxJOvnPAX9PxN3PYw-zD09_fMXCJ7PcwFHRftorMzB1pKUjbBa15ngkPWSyLFiy8RDP2pSB6lHZOIbEw-hElmsRNaTU4NGVmyP0verRTaaZ2OP5vSGLGuVxrBorNhK30Nm4SU_SkornfiHzCJt2SMo70cE6ZRHD4lTwC5EqIE0TSRuRwoTF8xWHNDISmMz5f1jjwbqvTTdqSpROmQhRr2UU5BSYnJddeVh9NiA9IAvA9b0FuDvfRDRupWjptegoNPqNe8WubUuRu9tM2oEWdlDSDJp7FIjR0lxpMxDyRgvmRCxSEJM4522ldSxmLzc7eIq7warDKGb9sIJYTT1ZNcGknGzlJCx4jtc7Il3hvlT91tTj3UQSfhL-EJ5_tRFPYj4fGMLPhme8dJwjBHkdf1jooAsgwfslIE3u47x--Bd3N9wuYkR9_EfZ6RtLTUA4-X5MIlnTRG2cVXlPFCYPtPJEB3TOuQd0o11iBZqtchra3wwmK_OY36sIH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