<div dir="ltr"><div>Thanks!</div><div><br></div>Philip, do you mean I should transform the original IR to something like this? (...which is what -expand-struct-regs can do, when applied to my original input)<br><br><div><font face="monospace, monospace">define void @main(%struct* byval %ptr) {</font></div><div><font face="monospace, monospace">  %val.index = getelementptr %struct* %ptr, i32 0, i32 0</font></div><div><font face="monospace, monospace">  %val.field = load i32* %val.index</font></div><div><font face="monospace, monospace">  %val.index1 = getelementptr %struct* %ptr, i32 0, i32 1</font></div><div><font face="monospace, monospace">  %val.field2 = load i32* %val.index1</font></div><div><font face="monospace, monospace">  %val.ptr = alloca %struct</font></div><div><font face="monospace, monospace">  %val.ptr.index = getelementptr %struct* %val.ptr, i32 0, i32 0</font></div><div><font face="monospace, monospace">  store i32 %val.field, i32* %val.ptr.index</font></div><div><font face="monospace, monospace">  %val.ptr.index4 = getelementptr %struct* %val.ptr, i32 0, i32 1</font></div><div><font face="monospace, monospace">  store i32 %val.field2, i32* %val.ptr.index4</font></div><div><font face="monospace, monospace">  call void @extern_func(%struct* byval %val.ptr)</font></div><div><font face="monospace, monospace">  ret void</font></div><div><font face="monospace, monospace">}</font></div><div><br></div><div>If so, would you mind pointing me to the phase that would reduce this? (I'm assuming that's what you meant by "for free" - there's an existing phase I could use)</div><div><br></div><div>Thank you.</div><div>Mircea.</div><div> </div><br><div class="gmail_quote">On Thu, Mar 5, 2015 at 4:39 PM Philip Reames <<a href="mailto:listmail@philipreames.com" target="_blank">listmail@philipreames.com</a>> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
  
    
  
  <div bgcolor="#FFFFFF" text="#000000">
    <div>Reid is right that this would go in
      memcpyopt, but... we there's an active discussion on the commit
      list which will solve this through a different mechanism.  There's
      an active desire to avoid teaching GVN and related pieces (of
      which memcpyopt is one) about first class aggregates.  We don't
      have enough active users of the feature to justify and maintain
      the complexity.  <br>
      <br>
      If you haven't already seen it, this background may help:
<a href="http://llvm.org/docs/Frontend/PerformanceTips.html#avoid-loads-and-stores-of-large-aggregate-type" target="_blank">http://llvm.org/docs/Frontend/<u></u>PerformanceTips.html#avoid-<u></u>loads-and-stores-of-large-<u></u>aggregate-type</a><br>
      <br>
      The current proposal is to convert such aggregate loads and stores
      into their component pieces.  If that happens, you're example
      should come "for free" provided that the same example works when
      you break down the FCA into it's component pieces.  If it doesn't,
      please say so.  <br></div></div><div bgcolor="#FFFFFF" text="#000000"><div>
      <br>
      Philip</div></div><div bgcolor="#FFFFFF" text="#000000"><div><br>
      <br>
      On 03/05/2015 04:21 PM, Reid Kleckner wrote:<br>
    </div></div><div bgcolor="#FFFFFF" text="#000000">
    <blockquote type="cite">
      <div dir="ltr">I think lib/Transforms/Scalar/<u></u>MemCpyOptimizer.cpp
        might be the right place for this, considering that most
        frontends will use memcpy for that copy anyway. It already has
        some logic for byval args.</div>
      <div class="gmail_extra"><br>
        <div class="gmail_quote">On Thu, Mar 5, 2015 at 3:51 PM, Mircea
          Trofin <span dir="ltr"><<a href="mailto:mtrofin@google.com" target="_blank">mtrofin@google.com</a>></span>
          wrote:<br>
          <blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
            <div dir="ltr">Hello all,
              <div><br>
              </div>
              <div>I'm trying to find the pass that would convert from:</div>
              <div>
                <div><br>
                </div>
                <div><font face="monospace, monospace">define void
                    @main(%struct* byval %ptr) {</font></div>
                <div><font face="monospace, monospace">  %val = load
                    %struct* %ptr</font></div>
                <div><font face="monospace, monospace">  %val.ptr =
                    alloca %struct</font></div>
                <div><font face="monospace, monospace">  store %struct
                    %val, %struct* %val.ptr</font></div>
                <div><font face="monospace, monospace">  call void
                    @extern_func(%struct* byval %val.ptr)</font></div>
                <div><font face="monospace, monospace">  ret void</font></div>
                <div><font face="monospace, monospace">}</font></div>
              </div>
              <div><br>
              </div>
              <div>to this:</div>
              <div>
                <div><font face="monospace, monospace">define void
                    @main(%struct* byval %ptr) {</font></div>
                <div><font face="monospace, monospace">  call void
                    @extern_func(%struct* byval %ptr)</font></div>
                <div><font face="monospace, monospace">  ret void</font></div>
                <div><font face="monospace, monospace">}</font></div>
              </div>
              <div><br>
              </div>
              <div>First, am I missing something - would this be a
                correct optimization?</div>
              <div><br>
              </div>
              <div>Thank you,</div>
              <div>Mircea.</div>
            </div>
            <br>
            ______________________________<u></u>_________________<br>
            LLVM Developers mailing list<br>
            <a href="mailto:LLVMdev@cs.uiuc.edu" target="_blank">LLVMdev@cs.uiuc.edu</a> 
                   <a href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a><br>
            <a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/<u></u>mailman/listinfo/llvmdev</a><br>
            <br>
          </blockquote>
        </div>
        <br>
      </div>
      <br>
      <fieldset></fieldset>
      <br>
      <pre>______________________________<u></u>_________________
LLVM Developers mailing list
<a href="mailto:LLVMdev@cs.uiuc.edu" target="_blank">LLVMdev@cs.uiuc.edu</a>         <a href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/<u></u>mailman/listinfo/llvmdev</a>
</pre>
    </blockquote>
    <br>
  </div></blockquote></div></div>