[PATCH] D11249: Fix PR#24142
Guozhi Wei
carrot at google.com
Wed Jul 15 16:44:54 PDT 2015
Carrot created this revision.
Carrot added a subscriber: llvm-commits.
Herald added a subscriber: aemerson.
Function getSPAdjust doesn't consider the stack alignment, its usage in PEI::replaceFrameIndices causes wrong offset is used for stack objects.
This patch adds a function to align the SP adjustment to the correct alignment, and call it from getSPAdjust and ARM backend. It can/should also be used by other backends if SP adjustment is need to be aligned.
http://reviews.llvm.org/D11249
Files:
include/llvm/Target/TargetFrameLowering.h
lib/CodeGen/TargetInstrInfo.cpp
lib/Target/ARM/ARMFrameLowering.cpp
Index: lib/Target/ARM/ARMFrameLowering.cpp
===================================================================
--- lib/Target/ARM/ARMFrameLowering.cpp
+++ lib/Target/ARM/ARMFrameLowering.cpp
@@ -1783,8 +1783,7 @@
// We need to keep the stack aligned properly. To do this, we round the
// amount of space needed for the outgoing arguments up to the next
// alignment boundary.
- unsigned Align = getStackAlignment();
- Amount = (Amount+Align-1)/Align*Align;
+ Amount = alignSPAdjust(Amount);
ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>();
assert(!AFI->isThumb1OnlyFunction() &&
Index: lib/CodeGen/TargetInstrInfo.cpp
===================================================================
--- lib/CodeGen/TargetInstrInfo.cpp
+++ lib/CodeGen/TargetInstrInfo.cpp
@@ -661,6 +661,7 @@
return 0;
int SPAdj = MI->getOperand(0).getImm();
+ SPAdj = TFI->alignSPAdjust(SPAdj);
if ((!StackGrowsDown && MI->getOpcode() == FrameSetupOpcode) ||
(StackGrowsDown && MI->getOpcode() == FrameDestroyOpcode))
Index: include/llvm/Target/TargetFrameLowering.h
===================================================================
--- include/llvm/Target/TargetFrameLowering.h
+++ include/llvm/Target/TargetFrameLowering.h
@@ -69,6 +69,20 @@
///
unsigned getStackAlignment() const { return StackAlignment; }
+ /// alignSPAdjust - This method aligns the stack adjustment to the correct
+ /// alignment.
+ ///
+ int alignSPAdjust(int SPAdj) const {
+ if (SPAdj < 0) {
+ SPAdj = -SPAdj;
+ SPAdj = (SPAdj + StackAlignment - 1) / StackAlignment * StackAlignment;
+ SPAdj = -SPAdj;
+ } else {
+ SPAdj = (SPAdj + StackAlignment - 1) / StackAlignment * StackAlignment;
+ }
+ return SPAdj;
+ }
+
/// getTransientStackAlignment - This method returns the number of bytes to
/// which the stack pointer must be aligned at all times, even between
/// calls.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D11249.29850.patch
Type: text/x-patch
Size: 1956 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150715/e052c334/attachment.bin>
More information about the llvm-commits
mailing list