[PATCH] LLVM miscompiles function call with struct parameter for AArch64 big-endian

Alexandros Lamprineas alexandros.lamprineas at arm.com
Wed Jun 3 09:09:37 PDT 2015


The attached code is miscompiled when targeting big-endian AArch64 at all
optimisation levels except for -O0. This should print "checksum = 00000008",
but actually prints "checksum = 00000000". It is correctly compiled if I
change the statement just before the function call from l_15.f0 to l_15.f1
(the result of this expression is unused). The only change this causes in
the IR is to change the parameter in the call to func_13 from 0x800000180 to
0x800018000.

The problem seems to be in llvm/lib/Transforms/Scalar/SROA.cpp. The 'Scalar
Replacement Of Aggregates' pass takes into account endianness, thus adds a
shift instruction when inserting an integer to an alloca store:

  if(DL.isBigEndian())

    ShAmt = 8 * (DL.getTypeStoreSize(IntTy) - DL.getTypeStoreSize(Ty) -
Offset);

In this particular example an integer value of wrong size ({i32}) is passed
as parameter to the function that computes the shift amount
('insertInteger'). This causes a zero shift amount since IntTy = {i64}, Ty =
{i32}, and offset = 4 bytes. My patch passes a parameter of Ty = {i24} to
'insertInteger'.


Alexandros Lamprineas

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150603/f200f57e/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test.c
Type: application/octet-stream
Size: 264 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150603/f200f57e/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: LLVM-2049_SROA.patch
Type: application/octet-stream
Size: 1993 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150603/f200f57e/attachment-0001.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: LLVM-2049_regressionTest.patch
Type: application/octet-stream
Size: 3499 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150603/f200f57e/attachment-0002.obj>


More information about the llvm-commits mailing list