[llvm] r245253 - Align SP adjustment in function getSPAdjust
Guozhi Wei via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 17 15:36:27 PDT 2015
Author: carrot
Date: Mon Aug 17 17:36:27 2015
New Revision: 245253
URL: http://llvm.org/viewvc/llvm-project?rev=245253&view=rev
Log:
Align SP adjustment in function getSPAdjust
This commit adds a new function TargetFrameLowering::alignSPAdjust
and calls it from TargetInstrInfo::getSPAdjust. It fixes PR24142.
Added:
llvm/trunk/test/CodeGen/ARM/align-sp-adjustment.ll
Modified:
llvm/trunk/include/llvm/Target/TargetFrameLowering.h
llvm/trunk/lib/CodeGen/TargetInstrInfo.cpp
llvm/trunk/lib/Target/ARM/ARMFrameLowering.cpp
Modified: llvm/trunk/include/llvm/Target/TargetFrameLowering.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Target/TargetFrameLowering.h?rev=245253&r1=245252&r2=245253&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Target/TargetFrameLowering.h (original)
+++ llvm/trunk/include/llvm/Target/TargetFrameLowering.h Mon Aug 17 17:36:27 2015
@@ -70,6 +70,18 @@ public:
///
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 = -RoundUpToAlignment(-SPAdj, StackAlignment);
+ } else {
+ SPAdj = RoundUpToAlignment(SPAdj, 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.
Modified: llvm/trunk/lib/CodeGen/TargetInstrInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/TargetInstrInfo.cpp?rev=245253&r1=245252&r2=245253&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/TargetInstrInfo.cpp (original)
+++ llvm/trunk/lib/CodeGen/TargetInstrInfo.cpp Mon Aug 17 17:36:27 2015
@@ -655,6 +655,7 @@ int TargetInstrInfo::getSPAdjust(const M
return 0;
int SPAdj = MI->getOperand(0).getImm();
+ SPAdj = TFI->alignSPAdjust(SPAdj);
if ((!StackGrowsDown && MI->getOpcode() == FrameSetupOpcode) ||
(StackGrowsDown && MI->getOpcode() == FrameDestroyOpcode))
Modified: llvm/trunk/lib/Target/ARM/ARMFrameLowering.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/ARMFrameLowering.cpp?rev=245253&r1=245252&r2=245253&view=diff
==============================================================================
--- llvm/trunk/lib/Target/ARM/ARMFrameLowering.cpp (original)
+++ llvm/trunk/lib/Target/ARM/ARMFrameLowering.cpp Mon Aug 17 17:36:27 2015
@@ -1734,8 +1734,7 @@ eliminateCallFramePseudoInstr(MachineFun
// 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() &&
Added: llvm/trunk/test/CodeGen/ARM/align-sp-adjustment.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/ARM/align-sp-adjustment.ll?rev=245253&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/ARM/align-sp-adjustment.ll (added)
+++ llvm/trunk/test/CodeGen/ARM/align-sp-adjustment.ll Mon Aug 17 17:36:27 2015
@@ -0,0 +1,47 @@
+; RUN: llc -mtriple=thumbv7 -o - %s | FileCheck %s
+
+; CHECK: [sp, #2120]
+
+%struct.struct_2 = type { [172 x %struct.struct_1] }
+%struct.struct_1 = type { i32, i32, i32 }
+
+ at .str = private unnamed_addr constant [2 x i8] c"a\00", align 1
+ at .str.1 = private unnamed_addr constant [2 x i8] c"b\00", align 1
+ at .str.2 = private unnamed_addr constant [2 x i8] c"c\00", align 1
+ at .str.3 = private unnamed_addr constant [2 x i8] c"d\00", align 1
+
+declare i32* @_Z4bar3iiPKcS0_i(i32, i32, i8*, i8*, i32)
+declare void @_Z4bar1i8struct_2(i32, %struct.struct_2* byval align 4)
+declare i32 @_Z4bar2PiPKc(i32*, i8*)
+
+define void @_Z3fooiiiii(i32 %p1, i32 %p2, i32 %p3, i32 %p4, i32 %p5) #0 {
+entry:
+ %params = alloca %struct.struct_2, align 4
+ %0 = bitcast %struct.struct_2* %params to i8*
+ br label %for.body
+
+for.body:
+ %i.015 = phi i32 [ 0, %entry ], [ %inc, %for.inc ]
+ %call = tail call i32* @_Z4bar3iiPKcS0_i(i32 %p1, i32 %p5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i32 0, i32 0), i32 %i.015) #4
+ %cmp1 = icmp eq i32* %call, null
+ br i1 %cmp1, label %cleanup.8, label %for.inc
+
+for.inc:
+ %call2 = tail call i32 @_Z4bar2PiPKc(i32* %call, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i32 0, i32 0)) #4
+ %f1 = getelementptr inbounds %struct.struct_2, %struct.struct_2* %params, i32 0, i32 0, i32 %i.015, i32 0
+ store i32 %call2, i32* %f1, align 4
+ %call3 = tail call i32 @_Z4bar2PiPKc(i32* %call, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i32 0, i32 0)) #4
+ %f2 = getelementptr inbounds %struct.struct_2, %struct.struct_2* %params, i32 0, i32 0, i32 %i.015, i32 1
+ store i32 %call3, i32* %f2, align 4
+ %inc = add nuw nsw i32 %i.015, 1
+ %cmp = icmp slt i32 %inc, 4
+ br i1 %cmp, label %for.body, label %for.end
+
+for.end:
+ call void @_Z4bar1i8struct_2(i32 %p4, %struct.struct_2* byval nonnull align 4 %params) #4
+ br label %cleanup.8
+
+cleanup.8:
+ ret void
+}
+
More information about the llvm-commits
mailing list