[PATCH] D104123: [llvm][AArch64] Handle arrays of struct properly (from IR)

David Spickett via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 11 08:13:21 PDT 2021


DavidSpickett created this revision.
Herald added subscribers: danielkiss, hiraditya, kristof.beyls.
DavidSpickett requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

This only applies to FastIsel. GlobalIsel seems to sidestep
the issue.

This fixes https://bugs.llvm.org/show_bug.cgi?id=46996

One of the things we do in llvm is decide if a type needs
consecutive registers. Previously, we just checked if it
was an array or not.
(plus an SVE specific check that is not changing here)

This causes some confusion when you arbitrary IR like:
%T1 = type { double, i1 };
define [ 1 x %T1 ] @foo() {
entry:

  ret [ 1 x %T1 ] zeroinitializer

}

We see it is an array so we call CC_AArch64_Custom_Block
which bails out when it sees the i1, a type we don't want
to put into a block.

This leaves the location of the double in some kind of
intermediate state and leads to odd codegen. Which then crashes
the backend because it doesn't know how to implement
what it's been asked for.

You get this:

  renamable $d0 = FMOVD0
  $w0 = COPY killed renamable $d0

Rather than this:

  $d0 = FMOVD0
  $w0 = COPY $wzr

The backend knows how to copy 64 bit to 64 bit registers,
but not 64 to 32. It can certainly be taught how but the real
issue seems to be us even trying to assign a register block
in the first place.

This change makes the logic of
AArch64TargetLowering::functionArgumentNeedsConsecutiveRegisters
a bit more in depth. If we find an array, also check that all the
nested aggregates in that array have a single member type.

Then CC_AArch64_Custom_Block's assumption of a type that looks
like [ N x type ] will be valid and we get the expected codegen.

New tests have been added to exercise these situations. Note that
some of the output is not ABI compliant. The aim of this change is
to simply handle these situations and not to make our processing
of arbitrary IR ABI compliant.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D104123

Files:
  llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
  llvm/test/CodeGen/AArch64/argument-blocks-array-of-struct.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D104123.351457.patch
Type: text/x-patch
Size: 13172 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210611/506d2d28/attachment.bin>


More information about the llvm-commits mailing list