<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/70207>70207</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[AArch64][GISel] Incorrect ABI for calls with tail marker
</td>
</tr>
<tr>
<th>Labels</th>
<td>
backend:AArch64,
miscompilation,
llvm:globalisel
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
nikic
</td>
</tr>
</table>
<pre>
```llvm
; RUN: llc -O0 -mtriple=aarch64-unknown-linux-gnu < %s | FileCheck %s
declare void @func(i64, i64, i64, i64, i64, i128, i128)
define void @test(i128 %arg1, i128 %arg2) nounwind {
tail call void @func(i64 0, i64 0, i64 0, i64 0, i64 0, i128 %arg1, i128 %arg2)
ret void
}
```
This produces:
```asm
sub sp, sp, #64
str x30, [sp, #48] // 8-byte Folded Spill
mov x6, x0
mov x8, sp
str x1, [x8]
str x2, [x8, #16]
str x3, [x8, #32]
mov x4, xzr
mov x0, x4
mov x1, x4
mov x2, x4
mov x3, x4
bl func
ldr x30, [sp, #48] // 8-byte Folded Reload
add sp, sp, #64
ret
```
Note that both of the i128 arguments get passed on the stack. Compare with the `-global-isel=0` output:
```asm
sub sp, sp, #32
str x30, [sp, #16] // 8-byte Folded Spill
mov x7, x1
mov x6, x0
mov x8, sp
str x3, [x8, #8]
str x2, [x8]
mov x4, xzr
mov x0, x4
mov x1, x4
mov x2, x4
mov x3, x4
bl func
ldr x30, [sp, #16] // 8-byte Folded Reload
add sp, sp, #32
ret
```
In this case the first i128 argument is passed in registers and only the second one on the stack.
Peculiarly, this does not happen when dropping the `tail` marker (which shouldn't make a difference as no actual tail call gets generated).
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzUls1u4zYQx5-GvgwcUJRsSQcf7BguctkWu-0DUORYYk2RAkklTp--ICXHWa-bALunBoE-hvT8hzM_csS9V61B3JDVjqz2Cz6GzrqNUSclFo2Vrx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