Index: lib/Target/ARM/ARMBaseRegisterInfo.cpp =================================================================== --- lib/Target/ARM/ARMBaseRegisterInfo.cpp +++ lib/Target/ARM/ARMBaseRegisterInfo.cpp @@ -524,7 +524,6 @@ // 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 Index: test/CodeGen/ARM/ssp-data-layout.ll =================================================================== --- test/CodeGen/ARM/ssp-data-layout.ll +++ test/CodeGen/ARM/ssp-data-layout.ll @@ -21,13 +21,13 @@ 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 @@ -35,27 +35,25 @@ ; 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 @@ -67,11 +65,11 @@ ; 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 @@ -83,7 +81,7 @@ ; 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 @@ -182,8 +180,6 @@ ; 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] @@ -202,7 +198,7 @@ ; 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 @@ -230,7 +226,7 @@ ; 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 @@ -317,8 +313,6 @@ ; 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] @@ -337,7 +331,7 @@ ; 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 @@ -365,7 +359,7 @@ ; 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 Index: test/CodeGen/Thumb/stack-access.ll =================================================================== --- test/CodeGen/Thumb/stack-access.ll +++ test/CodeGen/Thumb/stack-access.ll @@ -72,3 +72,19 @@ %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 +} \ No newline at end of file