<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<div class="moz-cite-prefix">Thanks. That kind of makes sense.<br>
<br>
I see that a lot in my code as well: poor IR structures that
aren't worth the effort to clean up since the LLVM passes do such
a fine job of it.<br>
<br>
Turns out I now have the same copying structure in my ABI support
code, though I use Store instead. :)<br>
<br>
<br>
On 19/04/18 19:26, David Blaikie wrote:<br>
</div>
<blockquote type="cite"
cite="mid:CAENS6EtHix7axY1vaP_5uYUU_m3ygoM+d3tWt50aOeMCMHZAaQ@mail.gmail.com">
<div dir="ltr">I believe the memcpy is there just as a consequence
of Clang's design - different parts of the compiler own
different pieces of this, so in some sense one hand doesn't see
what the other is doing. Part of it is "create an argument"
(memcpying the local variable into an unnamed value) and then
the next part is "oh, but that argument gets passed in
registers, so decompose it into registers again".<br>
<br>
Clang doesn't need to produce perfectly optimal IR - because the
optimization pipeline of LLVM will clean things up. So in many
cases it's just easier (& not a significant impediment to
performance) to have some of these sort of redundancies/oddities
in output, and just let the LLVM optimization pipeline clean
them up later.<br>
<br>
<div class="gmail_quote">
<div dir="ltr">On Wed, Apr 18, 2018 at 10:51 AM edA-qa
mort-ora-y via llvm-dev <<a
href="mailto:llvm-dev@lists.llvm.org"
moz-do-not-send="true">llvm-dev@lists.llvm.org</a>>
wrote:<br>
</div>
<blockquote class="gmail_quote" style="margin:0 0 0
.8ex;border-left:1px #ccc solid;padding-left:1ex">Yes, but
why is it even copying the memory? It already has a pointer<br>
which it can cast and load from -- and does so in other
scenarios.<br>
<br>
I'm wondering whether this copying is somehow required and
I'm missing<br>
something, or it's just an artifact of the clang emitter.
That is, could<br>
it not omit the memcpy and cast the original variable?<br>
<br>
On 18/04/18 19:43, Krzysztof Parzyszek via llvm-dev wrote:<br>
> This is the standard way of copying memory in the IR.
Backends can<br>
> expand the memcpy into loads/stores if they want.<br>
><br>
> -Krzysztof<br>
><br>
> On 4/18/2018 12:38 PM, edA-qa mort-ora-y via llvm-dev
wrote:<br>
>> Yes, I understand that as well (it's what I'm
trying to recreate in my<br>
>> language now).<br>
>><br>
>> I'm really wondering why it does the copy, since
from what I can tell it<br>
>> could just as easily cast the original value and do
the load without the<br>
>> memcpy operation.<br>
>><br>
>> That is, the question is about the memcpy and extra
alloca -- I<br>
>> understand what it's doing, just not why it's doing
it this way.<br>
>><br>
>><br>
>> On 18/04/18 19:33, Krzysztof Parzyszek via llvm-dev
wrote:<br>
>>> It is a matter of the calling convention. It
would specify what<br>
>>> structs are passed in registers, and which are
passed through stack.<br>
>>><br>
>>> -Krzysztof<br>
>>><br>
>>> On 4/18/2018 12:28 PM, edA-qa mort-ora-y via
llvm-dev wrote:<br>
>>>> I understand it's passing by value, that's
what I'm testing here. The<br>
>>>> question is why does it copy the data
rather than just casting and<br>
>>>> loading values from the original variable
(%v) ? It seems like the<br>
>>>> copying is unnecessary.<br>
>>>><br>
>>>> Not all struct's result in the copy, only
certain forms -- others are<br>
>>>> just cast directly as I was expecting. I'm
just not clear on what the<br>
>>>> differences are, and whether I need to do
the same thing.<br>
>>>><br>
>>>><br>
>>>> On 18/04/18 19:13, Dimitry Andric wrote:<br>
>>>>> On 18 Apr 2018, at 18:40, edA-qa
mort-ora-y via llvm-dev<br>
>>>>> <<a
href="mailto:llvm-dev@lists.llvm.org" target="_blank"
moz-do-not-send="true">llvm-dev@lists.llvm.org</a>>
wrote:<br>
>>>>>> I'm implementing function arguments
and tested this code in C:<br>
>>>>>><br>
>>>>>> // clang -emit-llvm
ll_struct_arg.c -S -o /dev/tty<br>
>>>>>> typedef struct vpt_data {<br>
>>>>>> char a;<br>
>>>>>> int b;<br>
>>>>>> float c;<br>
>>>>>> } vpt_data;<br>
>>>>>><br>
>>>>>> void vpt_test( vpt_data vd )
{<br>
>>>>>> }<br>
>>>>>><br>
>>>>>> int main() {<br>
>>>>>> vpt_data v;<br>
>>>>>> vpt_test(v);<br>
>>>>>> }<br>
>>>>>><br>
>>>>>> This emits an odd LLVM structure
that casts to the desired struct<br>
>>>>>> type,<br>
>>>>>> but also memcpy's to a temporary
structure. I'm unsure of why the<br>
>>>>>> memcpy<br>
>>>>>> is done as opposed to just casting
directly?<br>
>>>>> Because you are passing the parameter
by value? It *should* copy the<br>
>>>>> data. In this particular case it will
probably be elided if you<br>
>>>>> turn on<br>
>>>>> optimization, but it is more logical to
pass structs via a const<br>
>>>>> reference or pointer.<br>
>>>>><br>
>>>>> -Dimitry<br>
>>>>><br>
>>>><br>
>>>><br>
>>>><br>
>>>>
_______________________________________________<br>
>>>> LLVM Developers mailing list<br>
>>>> <a href="mailto:llvm-dev@lists.llvm.org"
target="_blank" moz-do-not-send="true">llvm-dev@lists.llvm.org</a><br>
>>>> <a
href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev"
rel="noreferrer" target="_blank" moz-do-not-send="true">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
>>>><br>
>>><br>
>><br>
><br>
<br>
-- <br>
edA-qa mort-ora-y <br>
<a href="http://mortoray.com/" rel="noreferrer"
target="_blank" moz-do-not-send="true">http://mortoray.com/</a><br>
<br>
Creator of the Leaf language<br>
<a href="http://leaflang.org/" rel="noreferrer"
target="_blank" moz-do-not-send="true">http://leaflang.org/</a><br>
<br>
Streaming algorithms, AI, and design on Twitch<br>
<a href="https://www.twitch.tv/mortoray"
rel="noreferrer" target="_blank" moz-do-not-send="true">https://www.twitch.tv/mortoray</a><br>
<br>
Twitter<br>
edaqa<br>
<br>
<br>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank"
moz-do-not-send="true">llvm-dev@lists.llvm.org</a><br>
<a
href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev"
rel="noreferrer" target="_blank" moz-do-not-send="true">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</blockquote>
</div>
</div>
</blockquote>
<p><br>
</p>
<pre class="moz-signature" cols="72">--
edA-qa mort-ora-y
<a class="moz-txt-link-freetext" href="http://mortoray.com/">http://mortoray.com/</a>
Creator of the Leaf language
<a class="moz-txt-link-freetext" href="http://leaflang.org/">http://leaflang.org/</a>
Streaming algorithms, AI, and design on Twitch
<a class="moz-txt-link-freetext" href="https://www.twitch.tv/mortoray">https://www.twitch.tv/mortoray</a>
Twitter
edaqa
</pre>
</body>
</html>