<html>
    <head>
      <base href="https://llvm.org/bugs/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - Inefficient passing of byval parameters"
   href="https://llvm.org/bugs/show_bug.cgi?id=27522">27522</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Inefficient passing of byval parameters
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libraries
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>Backend: X86
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>hans@chromium.org
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Consider:

  target datalayout = "e-m:x-p:32:32-i64:64-f80:32-n8:16:32-a:0:32-S32"
  target triple = "i686-pc-windows-msvc18.0.0"

  %struct.S = type { i32 }

  define void @f() {
  entry:
    %agg.tmp = alloca %struct.S
    %x = getelementptr inbounds %struct.S, %struct.S* %agg.tmp, i32 0, i32 0
    store i32 42, i32* %x
    call void @g(%struct.S* byval nonnull align 4 %agg.tmp) 
    ret void
  }

  declare void @g(%struct.S* byval align 4)


$ bin/llc /tmp/a.ll -o -

[..]
_f:                                     # @f
# BB#0:                                 # %entry
        subl    $8, %esp
        movl    $42, 4(%esp)
        movl    4(%esp), %eax
        movl    %eax, (%esp)
        calll   _g
        addl    $8, %esp
        retl

That's quite a round-about way to put 42 on the stack.


Another example:

  struct S {
    int x;
  };

  void g(S);

  void f(int x) {
    g({x});
  }

$ bin/clang++ -target i686-pc-win32 -O3 -S -o - /tmp/a.cc
[..]
# BB#0:                                 # %entry
        subl    $8, %esp
        movl    12(%esp), %eax
        movl    %eax, 4(%esp)
        movl    4(%esp), %eax
        movl    %eax, (%esp)
        calll   "?g@@YAXUS@@@Z"
        addl    $8, %esp
        retl

We could just jump to g() directly instead :-)</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>