Fix large stack alignment codegen for ARM and Thumb2 targets
authorKristof Beyls <kristof.beyls@arm.com>
Thu, 8 Jan 2015 15:09:14 +0000 (15:09 +0000)
committerKristof Beyls <kristof.beyls@arm.com>
Thu, 8 Jan 2015 15:09:14 +0000 (15:09 +0000)
commitd1cee9b3bc0d248734e57de4069f7a06714d8cf7
treee0a710aa34f3bb218b2671f7553e68b2f855eb73
parent9a6e4f08fe96257babf8b7d152b4768b31c3540a
Fix large stack alignment codegen for ARM and Thumb2 targets

This partially fixes PR13007 (ARM CodeGen fails with large stack
alignment): for ARM and Thumb2 targets, but not for Thumb1, as it
seems stack alignment for Thumb1 targets hasn't been supported at
all.

Producing an aligned stack pointer is done by zero-ing out the lower
bits of the stack pointer. The BIC instruction was used for this.
However, the immediate field of the BIC instruction only allows to
encode an immediate that can zero out up to a maximum of the 8 lower
bits. When a larger alignment is requested, a BIC instruction cannot
be used; llvm was silently producing incorrect code in this case.

This commit fixes code generation for large stack aligments by
using the BFC instruction instead, when the BFC instruction is
available.  When not, it uses 2 instructions: a right shift,
followed by a left shift to zero out the lower bits.

The lowering of ARM::Int_eh_sjlj_dispatchsetup still has code
that unconditionally uses BIC to realign the stack pointer, so it
very likely has the same problem. However, I wasn't able to
produce a test case for that. This commit adds an assert so that
the compiler will fail the assert instead of silently generating
wrong code if this is ever reached.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@225446 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Target/ARM/ARMExpandPseudoInsts.cpp
lib/Target/ARM/ARMFrameLowering.cpp
test/CodeGen/ARM/alloc-no-stack-realign.ll
test/CodeGen/ARM/fold-stack-adjust.ll
test/CodeGen/ARM/interrupt-attr.ll
test/CodeGen/ARM/spill-q.ll
test/CodeGen/ARM/stack-alignment.ll [new file with mode: 0644]
test/CodeGen/Thumb2/aligned-spill.ll
test/CodeGen/Thumb2/thumb2-spill-q.ll