2016-10-12 05:14:03 +08:00
|
|
|
; RUN: llc < %s -mtriple=thumb-apple-ios | FileCheck %s --check-prefix=CHECK --check-prefix=ALIGN4
|
|
|
|
; RUN: llc < %s -mtriple=thumb-none-eabi | FileCheck %s --check-prefix=CHECK --check-prefix=ALIGN8
|
[Thumb1] Re-write emitThumbRegPlusImmediate
This was motivated by a bug which caused code like this to be
miscompiled:
declare void @take_ptr(i8*)
define void @test() {
%addr1.32 = alloca i8
%addr2.32 = alloca i32, i32 1028
call void @take_ptr(i8* %addr1)
ret void
}
This was emitting the following assembly to get the value of %addr1:
add r0, sp, #1020
add r0, r0, #8
However, "add r0, r0, #8" is not a valid Thumb1 instruction, and this
could not be assembled. The generated object file contained this,
resulting in r0 holding SP+8 rather tha SP+1028:
add r0, sp, #1020
add r0, sp, #8
This function looked like it could have caused miscompilations for
other combinations of registers and offsets (though I don't think it is
currently called with these), and the heuristic it used did not match
the emitted code in all cases.
llvm-svn: 222125
2014-11-17 19:18:10 +08:00
|
|
|
; RUN: llc < %s -o %t -filetype=obj -mtriple=thumbv6-apple-ios
|
2016-10-12 05:14:03 +08:00
|
|
|
; RUN: llvm-objdump -triple=thumbv6-apple-ios -d %t | FileCheck %s --check-prefix=CHECK --check-prefix=ALIGN4
|
[Thumb1] Re-write emitThumbRegPlusImmediate
This was motivated by a bug which caused code like this to be
miscompiled:
declare void @take_ptr(i8*)
define void @test() {
%addr1.32 = alloca i8
%addr2.32 = alloca i32, i32 1028
call void @take_ptr(i8* %addr1)
ret void
}
This was emitting the following assembly to get the value of %addr1:
add r0, sp, #1020
add r0, r0, #8
However, "add r0, r0, #8" is not a valid Thumb1 instruction, and this
could not be assembled. The generated object file contained this,
resulting in r0 holding SP+8 rather tha SP+1028:
add r0, sp, #1020
add r0, sp, #8
This function looked like it could have caused miscompilations for
other combinations of registers and offsets (though I don't think it is
currently called with these), and the heuristic it used did not match
the emitted code in all cases.
llvm-svn: 222125
2014-11-17 19:18:10 +08:00
|
|
|
; RUN: llc < %s -o %t -filetype=obj -mtriple=thumbv6-none-eabi
|
2016-10-12 05:14:03 +08:00
|
|
|
; RUN: llvm-objdump -triple=thumbv6-none-eabi -d %t | FileCheck %s --check-prefix=CHECK --check-prefix=ALIGN8
|
2009-06-24 14:36:07 +08:00
|
|
|
|
[Thumb1] Re-write emitThumbRegPlusImmediate
This was motivated by a bug which caused code like this to be
miscompiled:
declare void @take_ptr(i8*)
define void @test() {
%addr1.32 = alloca i8
%addr2.32 = alloca i32, i32 1028
call void @take_ptr(i8* %addr1)
ret void
}
This was emitting the following assembly to get the value of %addr1:
add r0, sp, #1020
add r0, r0, #8
However, "add r0, r0, #8" is not a valid Thumb1 instruction, and this
could not be assembled. The generated object file contained this,
resulting in r0 holding SP+8 rather tha SP+1028:
add r0, sp, #1020
add r0, sp, #8
This function looked like it could have caused miscompilations for
other combinations of registers and offsets (though I don't think it is
currently called with these), and the heuristic it used did not match
the emitted code in all cases.
llvm-svn: 222125
2014-11-17 19:18:10 +08:00
|
|
|
; Largest stack for which a single tADDspi/tSUBspi is enough
|
2009-06-24 14:36:07 +08:00
|
|
|
define void @test1() {
|
2013-07-14 04:38:47 +08:00
|
|
|
; CHECK-LABEL: test1:
|
[Thumb1] Re-write emitThumbRegPlusImmediate
This was motivated by a bug which caused code like this to be
miscompiled:
declare void @take_ptr(i8*)
define void @test() {
%addr1.32 = alloca i8
%addr2.32 = alloca i32, i32 1028
call void @take_ptr(i8* %addr1)
ret void
}
This was emitting the following assembly to get the value of %addr1:
add r0, sp, #1020
add r0, r0, #8
However, "add r0, r0, #8" is not a valid Thumb1 instruction, and this
could not be assembled. The generated object file contained this,
resulting in r0 holding SP+8 rather tha SP+1028:
add r0, sp, #1020
add r0, sp, #8
This function looked like it could have caused miscompilations for
other combinations of registers and offsets (though I don't think it is
currently called with these), and the heuristic it used did not match
the emitted code in all cases.
llvm-svn: 222125
2014-11-17 19:18:10 +08:00
|
|
|
; CHECK: sub sp, #508
|
|
|
|
; CHECK: add sp, #508
|
|
|
|
%tmp = alloca [ 508 x i8 ] , align 4
|
2009-06-24 14:36:07 +08:00
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
[Thumb1] Re-write emitThumbRegPlusImmediate
This was motivated by a bug which caused code like this to be
miscompiled:
declare void @take_ptr(i8*)
define void @test() {
%addr1.32 = alloca i8
%addr2.32 = alloca i32, i32 1028
call void @take_ptr(i8* %addr1)
ret void
}
This was emitting the following assembly to get the value of %addr1:
add r0, sp, #1020
add r0, r0, #8
However, "add r0, r0, #8" is not a valid Thumb1 instruction, and this
could not be assembled. The generated object file contained this,
resulting in r0 holding SP+8 rather tha SP+1028:
add r0, sp, #1020
add r0, sp, #8
This function looked like it could have caused miscompilations for
other combinations of registers and offsets (though I don't think it is
currently called with these), and the heuristic it used did not match
the emitted code in all cases.
llvm-svn: 222125
2014-11-17 19:18:10 +08:00
|
|
|
; Largest stack for which three tADDspi/tSUBspis are enough
|
|
|
|
define void @test100() {
|
|
|
|
; CHECK-LABEL: test100:
|
|
|
|
; CHECK: sub sp, #508
|
|
|
|
; CHECK: sub sp, #508
|
|
|
|
; CHECK: sub sp, #508
|
[ARM] Generate consistent frame records for Thumb2
There is not an official documented ABI for frame pointers in Thumb2,
but we should try to emit something which is useful.
We use r7 as the frame pointer for Thumb code, which currently means
that if a function needs to save a high register (r8-r11), it will get
pushed to the stack between the frame pointer (r7) and link register
(r14). This means that while a stack unwinder can follow the chain of
frame pointers up the stack, it cannot know the offset to lr, so does
not know which functions correspond to the stack frames.
To fix this, we need to push the callee-saved registers in two batches,
with the first push saving the low registers, fp and lr, and the second
push saving the high registers. This is already implemented, but
previously only used for iOS. This patch turns it on for all Thumb2
targets when frame pointers are required by the ABI, and the frame
pointer is r7 (Windows uses r11, so this isn't a problem there). If
frame pointer elimination is enabled we still emit a single push/pop
even if we need a frame pointer for other reasons, to avoid increasing
code size.
We must also ensure that lr is pushed to the stack when using a frame
pointer, so that we end up with a complete frame record. Situations that
could cause this were rare, because we already push lr in most
situations so that we can return using the pop instruction.
Differential Revision: https://reviews.llvm.org/D23516
llvm-svn: 279506
2016-08-23 17:19:22 +08:00
|
|
|
; CHECK: add sp, #508
|
|
|
|
; CHECK: add sp, #508
|
|
|
|
; CHECK: add sp, #508
|
|
|
|
%tmp = alloca [ 1524 x i8 ] , align 4
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
|
|
|
; Largest stack for which three tADDspi/tSUBspis are enough
|
|
|
|
define void @test100_nofpelim() "no-frame-pointer-elim"="true" {
|
|
|
|
; CHECK-LABEL: test100_nofpelim:
|
|
|
|
; CHECK: sub sp, #508
|
|
|
|
; CHECK: sub sp, #508
|
|
|
|
; CHECK: sub sp, #508
|
2016-10-12 05:14:03 +08:00
|
|
|
; ALIGN4: subs r4, r7, #4
|
|
|
|
; ALIGN8: subs r4, r7, #7
|
|
|
|
; ALIGN8: subs r4, #1
|
[ARM] Generate consistent frame records for Thumb2
There is not an official documented ABI for frame pointers in Thumb2,
but we should try to emit something which is useful.
We use r7 as the frame pointer for Thumb code, which currently means
that if a function needs to save a high register (r8-r11), it will get
pushed to the stack between the frame pointer (r7) and link register
(r14). This means that while a stack unwinder can follow the chain of
frame pointers up the stack, it cannot know the offset to lr, so does
not know which functions correspond to the stack frames.
To fix this, we need to push the callee-saved registers in two batches,
with the first push saving the low registers, fp and lr, and the second
push saving the high registers. This is already implemented, but
previously only used for iOS. This patch turns it on for all Thumb2
targets when frame pointers are required by the ABI, and the frame
pointer is r7 (Windows uses r11, so this isn't a problem there). If
frame pointer elimination is enabled we still emit a single push/pop
even if we need a frame pointer for other reasons, to avoid increasing
code size.
We must also ensure that lr is pushed to the stack when using a frame
pointer, so that we end up with a complete frame record. Situations that
could cause this were rare, because we already push lr in most
situations so that we can return using the pop instruction.
Differential Revision: https://reviews.llvm.org/D23516
llvm-svn: 279506
2016-08-23 17:19:22 +08:00
|
|
|
; CHECK: mov sp, r4
|
[Thumb1] Re-write emitThumbRegPlusImmediate
This was motivated by a bug which caused code like this to be
miscompiled:
declare void @take_ptr(i8*)
define void @test() {
%addr1.32 = alloca i8
%addr2.32 = alloca i32, i32 1028
call void @take_ptr(i8* %addr1)
ret void
}
This was emitting the following assembly to get the value of %addr1:
add r0, sp, #1020
add r0, r0, #8
However, "add r0, r0, #8" is not a valid Thumb1 instruction, and this
could not be assembled. The generated object file contained this,
resulting in r0 holding SP+8 rather tha SP+1028:
add r0, sp, #1020
add r0, sp, #8
This function looked like it could have caused miscompilations for
other combinations of registers and offsets (though I don't think it is
currently called with these), and the heuristic it used did not match
the emitted code in all cases.
llvm-svn: 222125
2014-11-17 19:18:10 +08:00
|
|
|
%tmp = alloca [ 1524 x i8 ] , align 4
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
|
|
|
; Smallest stack for which we use a constant pool
|
2009-06-24 14:36:07 +08:00
|
|
|
define void @test2() {
|
2013-07-14 04:38:47 +08:00
|
|
|
; CHECK-LABEL: test2:
|
2015-12-09 03:59:01 +08:00
|
|
|
; CHECK: ldr [[TEMP:r[0-7]]],
|
|
|
|
; CHECK: add sp, [[TEMP]]
|
[ARM] Generate consistent frame records for Thumb2
There is not an official documented ABI for frame pointers in Thumb2,
but we should try to emit something which is useful.
We use r7 as the frame pointer for Thumb code, which currently means
that if a function needs to save a high register (r8-r11), it will get
pushed to the stack between the frame pointer (r7) and link register
(r14). This means that while a stack unwinder can follow the chain of
frame pointers up the stack, it cannot know the offset to lr, so does
not know which functions correspond to the stack frames.
To fix this, we need to push the callee-saved registers in two batches,
with the first push saving the low registers, fp and lr, and the second
push saving the high registers. This is already implemented, but
previously only used for iOS. This patch turns it on for all Thumb2
targets when frame pointers are required by the ABI, and the frame
pointer is r7 (Windows uses r11, so this isn't a problem there). If
frame pointer elimination is enabled we still emit a single push/pop
even if we need a frame pointer for other reasons, to avoid increasing
code size.
We must also ensure that lr is pushed to the stack when using a frame
pointer, so that we end up with a complete frame record. Situations that
could cause this were rare, because we already push lr in most
situations so that we can return using the pop instruction.
Differential Revision: https://reviews.llvm.org/D23516
llvm-svn: 279506
2016-08-23 17:19:22 +08:00
|
|
|
; CHECK: ldr [[TEMP:r[0-7]]],
|
|
|
|
; CHECK: add sp, [[TEMP]]
|
|
|
|
%tmp = alloca [ 1528 x i8 ] , align 4
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
|
|
|
; Smallest stack for which we use a constant pool
|
|
|
|
define void @test2_nofpelim() "no-frame-pointer-elim"="true" {
|
|
|
|
; CHECK-LABEL: test2_nofpelim:
|
|
|
|
; CHECK: ldr [[TEMP:r[0-7]]],
|
|
|
|
; CHECK: add sp, [[TEMP]]
|
2016-10-12 05:14:03 +08:00
|
|
|
; ALIGN4: subs r4, r7, #4
|
|
|
|
; ALIGN8: subs r4, r7, #7
|
|
|
|
; ALIGN8: subs r4, #1
|
[ARM] Generate consistent frame records for Thumb2
There is not an official documented ABI for frame pointers in Thumb2,
but we should try to emit something which is useful.
We use r7 as the frame pointer for Thumb code, which currently means
that if a function needs to save a high register (r8-r11), it will get
pushed to the stack between the frame pointer (r7) and link register
(r14). This means that while a stack unwinder can follow the chain of
frame pointers up the stack, it cannot know the offset to lr, so does
not know which functions correspond to the stack frames.
To fix this, we need to push the callee-saved registers in two batches,
with the first push saving the low registers, fp and lr, and the second
push saving the high registers. This is already implemented, but
previously only used for iOS. This patch turns it on for all Thumb2
targets when frame pointers are required by the ABI, and the frame
pointer is r7 (Windows uses r11, so this isn't a problem there). If
frame pointer elimination is enabled we still emit a single push/pop
even if we need a frame pointer for other reasons, to avoid increasing
code size.
We must also ensure that lr is pushed to the stack when using a frame
pointer, so that we end up with a complete frame record. Situations that
could cause this were rare, because we already push lr in most
situations so that we can return using the pop instruction.
Differential Revision: https://reviews.llvm.org/D23516
llvm-svn: 279506
2016-08-23 17:19:22 +08:00
|
|
|
; CHECK: mov sp, r4
|
[Thumb1] Re-write emitThumbRegPlusImmediate
This was motivated by a bug which caused code like this to be
miscompiled:
declare void @take_ptr(i8*)
define void @test() {
%addr1.32 = alloca i8
%addr2.32 = alloca i32, i32 1028
call void @take_ptr(i8* %addr1)
ret void
}
This was emitting the following assembly to get the value of %addr1:
add r0, sp, #1020
add r0, r0, #8
However, "add r0, r0, #8" is not a valid Thumb1 instruction, and this
could not be assembled. The generated object file contained this,
resulting in r0 holding SP+8 rather tha SP+1028:
add r0, sp, #1020
add r0, sp, #8
This function looked like it could have caused miscompilations for
other combinations of registers and offsets (though I don't think it is
currently called with these), and the heuristic it used did not match
the emitted code in all cases.
llvm-svn: 222125
2014-11-17 19:18:10 +08:00
|
|
|
%tmp = alloca [ 1528 x i8 ] , align 4
|
2009-06-24 14:36:07 +08:00
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
|
|
|
define i32 @test3() {
|
2013-07-14 04:38:47 +08:00
|
|
|
; CHECK-LABEL: test3:
|
2015-12-09 03:59:01 +08:00
|
|
|
; CHECK: ldr [[TEMP:r[0-7]]],
|
|
|
|
; CHECK: add sp, [[TEMP]]
|
2017-06-17 10:08:18 +08:00
|
|
|
; CHECK: ldr [[TEMP2:r[0-7]]],
|
|
|
|
; CHECK: add [[TEMP2]], sp
|
|
|
|
; CHECK: ldr [[TEMP3:r[0-7]]],
|
|
|
|
; CHECK: add sp, [[TEMP3]]
|
[ARM] Generate consistent frame records for Thumb2
There is not an official documented ABI for frame pointers in Thumb2,
but we should try to emit something which is useful.
We use r7 as the frame pointer for Thumb code, which currently means
that if a function needs to save a high register (r8-r11), it will get
pushed to the stack between the frame pointer (r7) and link register
(r14). This means that while a stack unwinder can follow the chain of
frame pointers up the stack, it cannot know the offset to lr, so does
not know which functions correspond to the stack frames.
To fix this, we need to push the callee-saved registers in two batches,
with the first push saving the low registers, fp and lr, and the second
push saving the high registers. This is already implemented, but
previously only used for iOS. This patch turns it on for all Thumb2
targets when frame pointers are required by the ABI, and the frame
pointer is r7 (Windows uses r11, so this isn't a problem there). If
frame pointer elimination is enabled we still emit a single push/pop
even if we need a frame pointer for other reasons, to avoid increasing
code size.
We must also ensure that lr is pushed to the stack when using a frame
pointer, so that we end up with a complete frame record. Situations that
could cause this were rare, because we already push lr in most
situations so that we can return using the pop instruction.
Differential Revision: https://reviews.llvm.org/D23516
llvm-svn: 279506
2016-08-23 17:19:22 +08:00
|
|
|
%retval = alloca i32, align 4
|
|
|
|
%tmp = alloca i32, align 4
|
|
|
|
%a = alloca [805306369 x i8], align 16
|
|
|
|
store i32 0, i32* %tmp
|
|
|
|
%tmp1 = load i32, i32* %tmp
|
|
|
|
ret i32 %tmp1
|
|
|
|
}
|
|
|
|
|
|
|
|
define i32 @test3_nofpelim() "no-frame-pointer-elim"="true" {
|
|
|
|
; CHECK-LABEL: test3_nofpelim:
|
|
|
|
; CHECK: ldr [[TEMP:r[0-7]]],
|
|
|
|
; CHECK: add sp, [[TEMP]]
|
2017-06-17 10:08:18 +08:00
|
|
|
; CHECK: ldr [[TEMP2:r[0-7]]],
|
|
|
|
; CHECK: add [[TEMP2]], sp
|
[ARM] Generate consistent frame records for Thumb2
There is not an official documented ABI for frame pointers in Thumb2,
but we should try to emit something which is useful.
We use r7 as the frame pointer for Thumb code, which currently means
that if a function needs to save a high register (r8-r11), it will get
pushed to the stack between the frame pointer (r7) and link register
(r14). This means that while a stack unwinder can follow the chain of
frame pointers up the stack, it cannot know the offset to lr, so does
not know which functions correspond to the stack frames.
To fix this, we need to push the callee-saved registers in two batches,
with the first push saving the low registers, fp and lr, and the second
push saving the high registers. This is already implemented, but
previously only used for iOS. This patch turns it on for all Thumb2
targets when frame pointers are required by the ABI, and the frame
pointer is r7 (Windows uses r11, so this isn't a problem there). If
frame pointer elimination is enabled we still emit a single push/pop
even if we need a frame pointer for other reasons, to avoid increasing
code size.
We must also ensure that lr is pushed to the stack when using a frame
pointer, so that we end up with a complete frame record. Situations that
could cause this were rare, because we already push lr in most
situations so that we can return using the pop instruction.
Differential Revision: https://reviews.llvm.org/D23516
llvm-svn: 279506
2016-08-23 17:19:22 +08:00
|
|
|
; CHECK: subs r4, r7,
|
|
|
|
; CHECK: mov sp, r4
|
2010-08-11 03:30:19 +08:00
|
|
|
%retval = alloca i32, align 4
|
|
|
|
%tmp = alloca i32, align 4
|
|
|
|
%a = alloca [805306369 x i8], align 16
|
|
|
|
store i32 0, i32* %tmp
|
2015-02-28 05:17:42 +08:00
|
|
|
%tmp1 = load i32, i32* %tmp
|
2010-08-11 03:30:19 +08:00
|
|
|
ret i32 %tmp1
|
2009-06-24 14:36:07 +08:00
|
|
|
}
|
2014-10-20 19:00:18 +08:00
|
|
|
|
|
|
|
; Here, the adds get optimized out because they are dead, but the calculation
|
|
|
|
; of the address of stack_a is dead but not optimized out. When the address
|
|
|
|
; calculation gets expanded to two instructions, we need to avoid reading a
|
|
|
|
; dead register.
|
|
|
|
; No CHECK lines (just test for crashes), as we hope this will be optimised
|
|
|
|
; better in future.
|
|
|
|
define i32 @test4() {
|
|
|
|
entry:
|
|
|
|
%stack_a = alloca i8, align 1
|
|
|
|
%stack_b = alloca [256 x i32*], align 4
|
|
|
|
%int = ptrtoint i8* %stack_a to i32
|
|
|
|
%add = add i32 %int, 1
|
|
|
|
br label %block2
|
|
|
|
|
|
|
|
block2:
|
|
|
|
%add2 = add i32 %add, 1
|
|
|
|
ret i32 0
|
|
|
|
}
|