Issue:
authorStepan Dyatkovskiy <stpworld@narod.ru>
Tue, 16 Oct 2012 07:16:47 +0000 (07:16 +0000)
committerStepan Dyatkovskiy <stpworld@narod.ru>
Tue, 16 Oct 2012 07:16:47 +0000 (07:16 +0000)
commite59a920b0c41c1e7e36a5c8d9d609aad87e4ec1e
treef52f03817031469ab820fb0756a3eb1d83e0a587
parent1705a999fad9de3d1b0368fa9793ae3b3db44015
Issue:
Stack is formed improperly for long structures passed as byval arguments for
EABI mode.

If we took AAPCS reference, we can found the next statements:

A: "If the argument requires double-word alignment (8-byte), the NCRN (Next
Core Register Number) is rounded up to the next even register number." (5.5
Parameter Passing, Stage C, C.3).

B: "The alignment of an aggregate shall be the alignment of its most-aligned
component." (4.3 Composite Types, 4.3.1 Aggregates).

So if we have structure with doubles (9 double fields) and 3 Core unused
registers (r1, r2, r3): caller should use r2 and r3 registers only.
Currently r1,r2,r3 set is used, but it is invalid.

Callee VA routine should also use r2 and r3 regs only. All is ok here. This
behaviour is guessed by rounding up SP address with ADD+BFC operations.

Fix:
Main fix is in ARMTargetLowering::HandleByVal. If we detected AAPCS mode and
8 byte alignment, we waste odd registers then.

P.S.:
I also improved LDRB_POST_IMM regression test. Since ldrb instruction will
not generated by current regression test after this patch.

llvm-svn: 166018
llvm/include/llvm/Target/TargetLowering.h
llvm/lib/CodeGen/CallingConvLower.cpp
llvm/lib/Target/ARM/ARMISelLowering.cpp
llvm/lib/Target/ARM/ARMISelLowering.h
llvm/test/CodeGen/ARM/2012-10-04-AAPCS-byval-align8.ll [new file with mode: 0644]
llvm/test/CodeGen/ARM/2012-10-04-LDRB_POST_IMM-Crash.ll