<div dir="ltr"><div dir="ltr">On Thu, Feb 25, 2021 at 5:00 PM Doerfert, Johannes <<a href="mailto:jdoerfert@anl.gov" target="_blank">jdoerfert@anl.gov</a>> wrote:<br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">To double check, the problem is the last argument here<br>
<a href="https://godbolt.org/z/Gqva4Y" rel="noreferrer" target="_blank">https://godbolt.org/z/Gqva4Y</a> does not carry the align(16)<br>
information anymore, correct?<br></blockquote><div><br></div><div>Basically, yes.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
If so, I don't see an immediate problem with allowing an "alignment"<br>
be applied to non-pointer values. The semantics would probably say<br>
that if the value is demoted to memory/stack, the associated alignment<br>
has to be guaranteed. As noted before [0], `align` is actually a hint<br>
and not a requirement. I'm unsure if we could not make it binding TBH,<br>
will think about that, interested in opinions.<br>
<br>
I take it we can't/don't want to legalize the constraints in the<br>
backend, right? I mean, use `%sturct.S* align(16) byval(%sturct.S) %p`<br>
in the IR. On that thought, what happens if we have a `struct S *`<br>
argument in source which we then promote to pass it by value?<br></blockquote><div><br></div><div>Yes, we wouldn't want to use byval in the frontend because it is best to use IR arguments that are lowered correctly regardless of their position in the argument list. Using byval usually forces the argument to be passed in memory, and that isn't correct if the six double arguments are removed from the original example. This has the surprising consequence that we can't, for example, remove arguments from vararg functions:</div><div><div><a href="https://reviews.llvm.org/rGe6e88f99b35f2fde5008e36f0d93f5231564b7d8">https://reviews.llvm.org/rGe6e88f99b35f2fde5008e36f0d93f5231564b7d8</a></div><div> And, generally, byval results in worse code at the call site than passing SSA values does.</div><div><br></div><div>If LLVM is able to do argument promotion, usually that means there is no ABI compatibility concern, and the arguments don't have to be aligned or arranged in any particular way. I think argument promotion in this case would pass each field individually.</div><div><br></div><div>----</div><div><br></div><div>I think what we need here is a new attribute, or a repurposed attribute, to control argument alignment. The original patch uses alignstack(n) for this purpose, which to date is used to control the stack pointer alignment for the whole call frame, and not for arguments. Do people like that, or is it confusing? If it's OK to use alignstack(n) on an argument, should we start using it on byval arguments in addition to align(), or is that just churn? Is it useful to have this kind of strong separation between ABI attributes and optimization hint attributes?</div><div></div></div></div></div>