[llvm-dev] Are calls with byval broken for AArch64 GlobalISel?

Arsenault, Matthew via llvm-dev llvm-dev at lists.llvm.org
Fri Mar 5 17:57:34 PST 2021


[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 value
str 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20210306/90a87dfe/attachment-0001.html>


More information about the llvm-dev mailing list