<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </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 - [AArch64][GlobalIsel] Cannot lower return of struct type with 9 fields"
   href="https://bugs.llvm.org/show_bug.cgi?id=50718">50718</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>[AArch64][GlobalIsel] Cannot lower return of struct type with 9 fields
          </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>enhancement
          </td>
        </tr>

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

        <tr>
          <th>Component</th>
          <td>GlobalISel
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>david.spickett@linaro.org
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org, quentin.colombet@gmail.com
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=24954" name="attach_24954" title="IR test file">attachment 24954</a> <a href="attachment.cgi?id=24954&action=edit" title="IR test file">[details]</a></span>
IR test file

This was found while working on <a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - Incorrect code generation for ARM with inline assembly"
   href="show_bug.cgi?id=50647">https://bugs.llvm.org/show_bug.cgi?id=50647</a>,
which deals with various combinations of aggregates and how registers are
assigned to them with FastIsel on AArch64.

I didn't find any issue with GlobalIsel apart from whenever we would need to
return by stack.

If you try to return a type like this:
%T1 = type { double,  double, double, double, double, double, double, double,
double }

When we try to lower the return we run out of D registers (0-7 is allowed for
argument passing and return) and so fail and there appears to be no fallback
path to put the argument on the stack.
(though I'm unfamiliar with globalisel so maybe I have some strict mode on, and
it could fall back somehow)

./bin/llc -mtriple=aarch64-none-linux-gnu -o - test.ll -global-isel

LLVM ERROR: unable to translate instruction: ret (in function:
return_argument_1)
PLEASE submit a bug report to <a href="https://bugs.llvm.org/">https://bugs.llvm.org/</a> and include the crash
backtrace.
Stack dump:
0.      Program arguments: /home/david.spickett/build-llvm-aarch64/bin/llc
-mtriple=aarch64-none-linux-gnu -o -
/home/david.spickett/llvm-project/llvm/test/CodeGen/AArch64/argument-blocks-array-of-struct.ll
-global-isel
1.      Running pass 'Function Pass Manager' on module
'/home/david.spickett/llvm-project/llvm/test/CodeGen/AArch64/argument-blocks-array-of-struct.ll'.
2.      Running pass 'IRTranslator' on function '@return_argument_1'
#0 0x0000aaaac0e2e2c8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int)
/home/david.spickett/llvm-project/llvm/lib/Support/Unix/Signals.inc:565:0
Aborted (core dumped)

If you have 8 items in the type it uses d0-d7 registers as expected.

If you try to do the same thing from C it works probably because something else
transforms the IR so you don't have to ask for 9 registers.

Godbolt with both examples: <a href="https://godbolt.org/z/3j7qoPvhf">https://godbolt.org/z/3j7qoPvhf</a> (files also
attached)</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>