[AMD Public Use]
I noticed the byval handling is largely missing from the GlobalISel call lowering implementation, and noticed AArch64 is producing different code vs. SelectionDAG. Specifically, it is not copying byval argument contents and is just directly passing the pointer. If the callee were to modify the memory, it would incorrectly overwrite the caller’s value.
Consider this minimal example:
define i32 @call_byval(i32 %arg0) {
%alloca = alloca i32
%ret = call i32 @callee(i32* byval %alloca)
ret i32 %ret
}
For SelectionDAG, this inserts a copy:
sub sp, sp, #32
str x30, [sp, #16]
.cfi_def_cfa_offset 32
.cfi_offset w30, -16
ldr w8, [sp, #28] // Read valuestr w8, [sp] // Copy to outgoing slot
bl callee
For GlobalISel, this copy is missing:
sub sp, sp, #32
str x30, [sp, #16]
.cfi_def_cfa_offset 32
.cfi_offset w30, -16
bl callee
-Matt