Skip to content

Commit

Permalink
[ARM] Fix offset calculation in ARMBaseRegisterInfo::needsFrameBaseReg
Browse files Browse the repository at this point in the history
The input offset to needsFrameBaseReg is a negative value below the top of the
stack frame, but when converting to a positive offset from the bottom of the
stack frame this value was negated, causing the final offset to be too large
by twice the input offset's magnitude. Fix that by not negating the offset.

Patch by John Brawn

Differential Revision: http://reviews.llvm.org/D8316

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@232513 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
RichBarton-Arm committed Mar 17, 2015
1 parent de39837 commit b59aee1
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 26 deletions.
1 change: 0 additions & 1 deletion lib/Target/ARM/ARMBaseRegisterInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,6 @@ needsFrameBaseReg(MachineInstr *MI, int64_t Offset) const {
// The incoming offset is relating to the SP at the start of the function,
// but when we access the local it'll be relative to the SP after local
// allocation, so adjust our SP-relative offset by that allocation size.
Offset = -Offset;
Offset += MFI->getLocalFrameSize();
// Assume that we'll have at least some spill slots allocated.
// FIXME: This is a total SWAG number. We should run some statistics
Expand Down
44 changes: 19 additions & 25 deletions test/CodeGen/ARM/ssp-data-layout.ll
Original file line number Diff line number Diff line change
Expand Up @@ -21,41 +21,39 @@
define void @layout_ssp() ssp {
entry:
; Expected stack layout for ssp is
; 180 large_char . Group 1, nested arrays, arrays >= ssp-buffer-size
; 172 struct_large_char .
; 168 scalar1 | Everything else
; 164 scalar2
; 160 scalar3
; 156 addr-of
; 152 small_nonchar (84+68)
; 176 large_char . Group 1, nested arrays, arrays >= ssp-buffer-size
; 168 struct_large_char .
; 164 scalar1 | Everything else
; 160 scalar2
; 156 scalar3
; 152 addr-of
; 148 small_nonchar
; 112 large_nonchar
; 110 small_char
; 108 struct_small_char
; 72 struct_large_nonchar
; 68 struct_small_nonchar

; CHECK: layout_ssp:
; r[[SP]] is used as an offset into the stack later
; CHECK: add r[[SP:[0-9]+]], sp, #68

; CHECK: bl get_scalar1
; CHECK: str r0, [sp, #168]
; CHECK: str r0, [sp, #164]
; CHECK: bl end_scalar1

; CHECK: bl get_scalar2
; CHECK: str r0, [sp, #164]
; CHECK: str r0, [sp, #160]
; CHECK: bl end_scalar2

; CHECK: bl get_scalar3
; CHECK: str r0, [sp, #160]
; CHECK: str r0, [sp, #156]
; CHECK: bl end_scalar3

; CHECK: bl get_addrof
; CHECK: str r0, [sp, #156]
; CHECK: str r0, [sp, #152]
; CHECK: bl end_addrof

; CHECK: get_small_nonchar
; CHECK: strh r0, [r[[SP]], #84]
; CHECK: strh r0, [sp, #148]
; CHECK: bl end_small_nonchar

; CHECK: bl get_large_nonchar
Expand All @@ -67,11 +65,11 @@ entry:
; CHECK: bl end_small_char

; CHECK: bl get_large_char
; CHECK: strb r0, [sp, #180]
; CHECK: strb r0, [sp, #176]
; CHECK: bl end_large_char

; CHECK: bl get_struct_large_char
; CHECK: strb r0, [sp, #172]
; CHECK: strb r0, [sp, #168]
; CHECK: bl end_struct_large_char

; CHECK: bl get_struct_small_char
Expand All @@ -83,7 +81,7 @@ entry:
; CHECK: bl end_struct_large_nonchar

; CHECK: bl get_struct_small_nonchar
; CHECK: strh r0, [r[[SP]]]
; CHECK: strh r0, [sp, #68]
; CHECK: bl end_struct_small_nonchar
%x = alloca i32, align 4
%y = alloca i32, align 4
Expand Down Expand Up @@ -182,8 +180,6 @@ entry:
; 68 scalar3 +
;
; CHECK: layout_sspstrong:
; r[[SP]] is used as an offset into the stack later
; CHECK: add r[[SP:[0-9]+]], sp, #84

; CHECK: bl get_scalar1
; CHECK: str r0, [sp, #76]
Expand All @@ -202,7 +198,7 @@ entry:
; CHECK: bl end_addrof

; CHECK: get_small_nonchar
; CHECK: strh r0, [r[[SP]], #8]
; CHECK: strh r0, [sp, #92]
; CHECK: bl end_small_nonchar

; CHECK: bl get_large_nonchar
Expand Down Expand Up @@ -230,7 +226,7 @@ entry:
; CHECK: bl end_struct_large_nonchar

; CHECK: bl get_struct_small_nonchar
; CHECK: strh r0, [r[[SP]]]
; CHECK: strh r0, [sp, #84]
; CHECK: bl end_struct_small_nonchar
%x = alloca i32, align 4
%y = alloca i32, align 4
Expand Down Expand Up @@ -317,8 +313,6 @@ entry:
; Expected stack layout for sspreq is the same as sspstrong
;
; CHECK: layout_sspreq:
; r[[SP]] is used as an offset into the stack later
; CHECK: add r[[SP:[0-9]+]], sp, #84

; CHECK: bl get_scalar1
; CHECK: str r0, [sp, #76]
Expand All @@ -337,7 +331,7 @@ entry:
; CHECK: bl end_addrof

; CHECK: get_small_nonchar
; CHECK: strh r0, [r[[SP]], #8]
; CHECK: strh r0, [sp, #92]
; CHECK: bl end_small_nonchar

; CHECK: bl get_large_nonchar
Expand Down Expand Up @@ -365,7 +359,7 @@ entry:
; CHECK: bl end_struct_large_nonchar

; CHECK: bl get_struct_small_nonchar
; CHECK: strh r0, [r[[SP]]]
; CHECK: strh r0, [sp, #84]
; CHECK: bl end_struct_small_nonchar
%x = alloca i32, align 4
%y = alloca i32, align 4
Expand Down
16 changes: 16 additions & 0 deletions test/CodeGen/Thumb/stack-access.ll
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,19 @@ define zeroext i16 @test6() {
%1 = load i16, i16* %x, align 2
ret i16 %1
}

; Accessing the bottom of a large array shouldn't require materializing a base
define void @test7() {
%arr = alloca [200 x i32], align 4

; CHECK: movs [[REG:r[0-9]+]], #1
; CHECK: str [[REG]], [sp, #4]
%arrayidx = getelementptr inbounds [200 x i32], [200 x i32]* %arr, i32 0, i32 1
store i32 1, i32* %arrayidx, align 4

; CHECK: str [[REG]], [sp, #16]
%arrayidx1 = getelementptr inbounds [200 x i32], [200 x i32]* %arr, i32 0, i32 4
store i32 1, i32* %arrayidx1, align 4

ret void
}

0 comments on commit b59aee1

Please sign in to comment.