<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<p style="font-family:Arial;font-size:10pt;color:#317100;margin:15pt;" align="Left">
[AMD Public Use]<br>
</p>
<br>
<div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
The incoming direction also looks totally broken:</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
define void @test_byval(i8* byval(i8) %ptr) {
<div>  %load = load volatile i8, i8* %ptr</div>
<div>  ret void</div>
<div>}</div>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
// SDAG:  <br>
<blockquote style="margin-top:0;margin-bottom:0">
<div>.cfi_startproc</div>
<div>ldrb w8, [sp]</div>
ret</blockquote>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
// GISel:</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<blockquote style="margin-top:0;margin-bottom:0">.cfi_startproc
<div>; %bb.0:</div>
<div>ldr x8, [sp]</div>
<div>ldrb wzr, [x8]</div>
<div>ret<br>
</div>
</blockquote>
<div><br>
</div>
<div>I have a patch which fixes this second half, but wanted to confirm this is fixing the AArch64 ABI and not breaking it</div>
<div><br>
</div>
<div>-Matt<br>
</div>
</div>
<div id="appendonsend"></div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> llvm-dev <llvm-dev-bounces@lists.llvm.org> on behalf of Arsenault, Matthew via llvm-dev <llvm-dev@lists.llvm.org><br>
<b>Sent:</b> Friday, March 5, 2021 8:57 PM<br>
<b>To:</b> llvm-dev <llvm-dev@lists.llvm.org><br>
<b>Subject:</b> [llvm-dev] Are calls with byval broken for AArch64 GlobalISel?</font>
<div> </div>
</div>
<style type="text/css" style="display:none">
<!--
p
        {margin-top:0;
        margin-bottom:0}
-->
</style>
<div dir="ltr">
<p align="Left" style="font-family:Arial; font-size:10pt; color:#317100; margin:15pt">
[AMD Public Use]<br>
</p>
<br>
<div>[CAUTION: External Email]
<div>
<p align="Left" style="font-family:Arial; font-size:10pt; color:#317100; margin:15pt">
[AMD Public Use]<br>
</p>
<br>
<div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
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.<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
Consider this minimal example:</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
define i32 @call_byval(i32 %arg0) {
<div>  %alloca = alloca i32</div>
<div>  %ret = call i32 @callee(i32* byval %alloca)</div>
<div>  ret i32 %ret</div>
}</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
For SelectionDAG, this inserts a copy:</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<blockquote style="margin-top:0; margin-bottom:0">sub sp, sp, #32                  
<br>
<div>str x30, [sp, #16]<br>
</div>
<div>.cfi_def_cfa_offset 32</div>
<div>.cfi_offset w30, -16</div>
<div>ldr w8, [sp, #28] // Read value<br>
</div>
<div>str w8, [sp]  // Copy to outgoing slot<br>
</div>
bl callee</blockquote>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
For GlobalISel, this copy is missing:</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<blockquote style="margin-top:0; margin-bottom:0">sub sp, sp, #32<br>
<div>str x30, [sp, #16]<br>
</div>
<div>.cfi_def_cfa_offset 32</div>
<div>.cfi_offset w30, -16</div>
bl callee<br>
</blockquote>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
-Matt<br>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>