2020-06-16 06:31:10 +08:00
|
|
|
; RUN: llc < %s --mtriple=wasm32-unknown-unknown -asm-verbose=false -disable-wasm-fallthrough-return-opt -wasm-keep-registers | FileCheck -DPTR=32 %s
|
|
|
|
; RUN: llc < %s --mtriple=wasm64-unknown-unknown -asm-verbose=false -disable-wasm-fallthrough-return-opt -wasm-keep-registers | FileCheck -DPTR=64 %s
|
2015-12-12 07:49:46 +08:00
|
|
|
|
2016-02-24 02:13:07 +08:00
|
|
|
declare void @ext_func(i64* %ptr)
|
|
|
|
declare void @ext_func_i32(i32* %ptr)
|
|
|
|
|
2015-12-12 07:49:46 +08:00
|
|
|
; CHECK-LABEL: alloca32:
|
2015-12-17 04:43:06 +08:00
|
|
|
; Check that there is an extra local for the stack pointer.
|
2020-06-16 06:31:10 +08:00
|
|
|
; CHECK: .local i[[PTR]]{{$}}
|
2016-02-24 02:13:07 +08:00
|
|
|
define void @alloca32() noredzone {
|
2019-02-23 08:07:39 +08:00
|
|
|
; CHECK-NEXT: global.get $push[[L2:.+]]=, __stack_pointer{{$}}
|
2020-06-16 06:31:10 +08:00
|
|
|
; CHECK-NEXT: i[[PTR]].const $push[[L3:.+]]=, 16
|
|
|
|
; CHECK-NEXT: i[[PTR]].sub $push[[L9:.+]]=, $pop[[L2]], $pop[[L3]]
|
2019-01-08 14:25:55 +08:00
|
|
|
; CHECK-NEXT: local.tee $push[[L8:.+]]=, [[SP:.+]], $pop[[L9]]{{$}}
|
2019-02-23 08:07:39 +08:00
|
|
|
; CHECK-NEXT: global.set __stack_pointer, $pop[[L8]]{{$}}
|
2015-12-12 07:49:46 +08:00
|
|
|
%retval = alloca i32
|
2019-01-08 14:25:55 +08:00
|
|
|
; CHECK: local.get $push[[L4:.+]]=, [[SP]]{{$}}
|
2016-02-21 05:46:50 +08:00
|
|
|
; CHECK: i32.const $push[[L0:.+]]=, 0
|
2017-03-01 07:37:04 +08:00
|
|
|
; CHECK: i32.store 12($pop[[L4]]), $pop[[L0]]
|
2015-12-12 07:49:46 +08:00
|
|
|
store i32 0, i32* %retval
|
2019-01-08 14:25:55 +08:00
|
|
|
; CHECK: local.get $push[[L6:.+]]=, [[SP]]{{$}}
|
2020-06-16 06:31:10 +08:00
|
|
|
; CHECK-NEXT: i[[PTR]].const $push[[L5:.+]]=, 16
|
|
|
|
; CHECK-NEXT: i[[PTR]].add $push[[L7:.+]]=, $pop[[L6]], $pop[[L5]]
|
2019-02-23 08:07:39 +08:00
|
|
|
; CHECK-NEXT: global.set __stack_pointer, $pop[[L7]]
|
2015-12-12 07:49:46 +08:00
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
|
|
|
; CHECK-LABEL: alloca3264:
|
2020-06-16 06:31:10 +08:00
|
|
|
; CHECK: .local i[[PTR]]{{$}}
|
2015-12-12 07:49:46 +08:00
|
|
|
define void @alloca3264() {
|
2019-02-23 08:07:39 +08:00
|
|
|
; CHECK: global.get $push[[L3:.+]]=, __stack_pointer{{$}}
|
2020-06-16 06:31:10 +08:00
|
|
|
; CHECK-NEXT: i[[PTR]].const $push[[L4:.+]]=, 16
|
|
|
|
; CHECK-NEXT: i[[PTR]].sub $push[[L6:.+]]=, $pop[[L3]], $pop[[L4]]
|
2019-01-08 14:25:55 +08:00
|
|
|
; CHECK-NEXT: local.tee $push[[L5:.+]]=, [[SP:.+]], $pop[[L6]]
|
2015-12-12 07:49:46 +08:00
|
|
|
%r1 = alloca i32
|
|
|
|
%r2 = alloca double
|
|
|
|
store i32 0, i32* %r1
|
2017-07-18 16:20:50 +08:00
|
|
|
store double 0.0, double* %r2
|
2017-07-19 12:15:30 +08:00
|
|
|
; CHECK-NEXT: i64.const $push[[L1:.+]]=, 0
|
|
|
|
; CHECK-NEXT: i64.store 0($pop[[L5]]), $pop[[L1]]
|
2019-01-08 14:25:55 +08:00
|
|
|
; CHECK-NEXT: local.get $push[[L2:.+]]=, [[SP]]{{$}}
|
2017-07-19 12:15:30 +08:00
|
|
|
; CHECK-NEXT: i32.const $push[[L0:.+]]=, 0
|
|
|
|
; CHECK-NEXT: i32.store 12($pop[[L2]]), $pop[[L0]]
|
2016-02-24 02:13:07 +08:00
|
|
|
; CHECK-NEXT: return
|
2015-12-12 07:49:46 +08:00
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
2015-12-17 04:43:06 +08:00
|
|
|
; CHECK-LABEL: allocarray:
|
2020-06-16 06:31:10 +08:00
|
|
|
; CHECK: .local i[[PTR]]{{$}}
|
2015-12-12 07:49:46 +08:00
|
|
|
define void @allocarray() {
|
2019-02-23 08:07:39 +08:00
|
|
|
; CHECK-NEXT: global.get $push[[L4:.+]]=, __stack_pointer{{$}}
|
2020-06-16 06:31:10 +08:00
|
|
|
; CHECK-NEXT: i[[PTR]].const $push[[L5:.+]]=, 144{{$}}
|
|
|
|
; CHECK-NEXT: i[[PTR]].sub $push[[L12:.+]]=, $pop[[L4]], $pop[[L5]]
|
2019-01-08 14:25:55 +08:00
|
|
|
; CHECK-NEXT: local.tee $push[[L11:.+]]=, 0, $pop[[L12]]
|
2019-02-23 08:07:39 +08:00
|
|
|
; CHECK-NEXT: global.set __stack_pointer, $pop[[L11]]
|
2016-02-24 02:13:07 +08:00
|
|
|
%r = alloca [33 x i32]
|
2016-01-20 12:21:16 +08:00
|
|
|
|
2020-06-16 06:31:10 +08:00
|
|
|
; CHECK: i[[PTR]].const $push{{.+}}=, 24
|
|
|
|
; CHECK-NEXT: i[[PTR]].add $push[[L3:.+]]=, $pop{{.+}}, $pop{{.+}}
|
2016-05-10 12:24:02 +08:00
|
|
|
; CHECK-NEXT: i32.const $push[[L1:.+]]=, 1{{$}}
|
2016-10-07 06:08:28 +08:00
|
|
|
; CHECK-NEXT: i32.store 0($pop[[L3]]), $pop[[L1]]{{$}}
|
2019-01-08 14:25:55 +08:00
|
|
|
; CHECK-NEXT: local.get $push[[L4:.+]]=, 0{{$}}
|
2016-08-19 01:51:27 +08:00
|
|
|
; CHECK-NEXT: i32.const $push[[L10:.+]]=, 1{{$}}
|
2017-03-01 07:37:04 +08:00
|
|
|
; CHECK-NEXT: i32.store 12($pop[[L4]]), $pop[[L10]]{{$}}
|
2016-02-24 02:13:07 +08:00
|
|
|
%p = getelementptr [33 x i32], [33 x i32]* %r, i32 0, i32 0
|
2015-12-12 07:49:46 +08:00
|
|
|
store i32 1, i32* %p
|
2016-02-24 02:13:07 +08:00
|
|
|
%p2 = getelementptr [33 x i32], [33 x i32]* %r, i32 0, i32 3
|
2015-12-12 07:49:46 +08:00
|
|
|
store i32 1, i32* %p2
|
2016-01-20 12:21:16 +08:00
|
|
|
|
2019-01-08 14:25:55 +08:00
|
|
|
; CHECK-NEXT: local.get $push[[L2:.+]]=, [[SP]]{{$}}
|
2020-06-16 06:31:10 +08:00
|
|
|
; CHECK-NEXT: i[[PTR]].const $push[[L7:.+]]=, 144
|
|
|
|
; CHECK-NEXT: i[[PTR]].add $push[[L8:.+]]=, $pop[[L2]], $pop[[L7]]
|
2019-02-23 08:07:39 +08:00
|
|
|
; CHECK-NEXT: global.set __stack_pointer, $pop[[L8]]
|
2015-12-12 07:49:46 +08:00
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
2016-01-27 06:47:43 +08:00
|
|
|
; CHECK-LABEL: non_mem_use
|
2016-01-31 05:43:08 +08:00
|
|
|
define void @non_mem_use(i8** %addr) {
|
2020-06-16 06:31:10 +08:00
|
|
|
; CHECK: i[[PTR]].const $push[[L2:.+]]=, 48
|
|
|
|
; CHECK-NEXT: i[[PTR]].sub $push[[L12:.+]]=, {{.+}}, $pop[[L2]]
|
2019-01-08 14:25:55 +08:00
|
|
|
; CHECK-NEXT: local.tee $push[[L11:.+]]=, [[SP:.+]], $pop[[L12]]
|
2019-02-23 08:07:39 +08:00
|
|
|
; CHECK-NEXT: global.set __stack_pointer, $pop[[L11]]
|
2016-01-31 05:43:08 +08:00
|
|
|
%buf = alloca [27 x i8], align 16
|
2016-01-27 06:47:43 +08:00
|
|
|
%r = alloca i64
|
|
|
|
%r2 = alloca i64
|
|
|
|
; %r is at SP+8
|
2019-01-08 14:25:55 +08:00
|
|
|
; CHECK: local.get $push[[L3:.+]]=, [[SP]]
|
2020-06-16 06:31:10 +08:00
|
|
|
; CHECK: i[[PTR]].const $push[[OFF:.+]]=, 8
|
|
|
|
; CHECK-NEXT: i[[PTR]].add $push[[ARG1:.+]]=, $pop[[L3]], $pop[[OFF]]
|
2019-02-23 08:07:39 +08:00
|
|
|
; CHECK-NEXT: call ext_func, $pop[[ARG1]]
|
2016-01-27 06:47:43 +08:00
|
|
|
call void @ext_func(i64* %r)
|
|
|
|
; %r2 is at SP+0, no add needed
|
2019-01-08 14:25:55 +08:00
|
|
|
; CHECK: local.get $push[[L4:.+]]=, [[SP]]
|
2019-02-23 08:07:39 +08:00
|
|
|
; CHECK-NEXT: call ext_func, $pop[[L4]]
|
2016-01-27 06:47:43 +08:00
|
|
|
call void @ext_func(i64* %r2)
|
2016-01-31 05:43:08 +08:00
|
|
|
; Use as a value, but in a store
|
|
|
|
; %buf is at SP+16
|
2019-01-08 14:25:55 +08:00
|
|
|
; CHECK: local.get $push[[L5:.+]]=, [[SP]]
|
2020-06-16 06:31:10 +08:00
|
|
|
; CHECK: i[[PTR]].const $push[[OFF:.+]]=, 16
|
|
|
|
; CHECK-NEXT: i[[PTR]].add $push[[VAL:.+]]=, $pop[[L5]], $pop[[OFF]]
|
|
|
|
; CHECK-NEXT: i[[PTR]].store 0($pop{{.+}}), $pop[[VAL]]
|
2016-01-31 05:43:08 +08:00
|
|
|
%gep = getelementptr inbounds [27 x i8], [27 x i8]* %buf, i32 0, i32 0
|
|
|
|
store i8* %gep, i8** %addr
|
2016-01-27 06:47:43 +08:00
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
2016-01-20 12:21:16 +08:00
|
|
|
; CHECK-LABEL: allocarray_inbounds:
|
2020-06-16 06:31:10 +08:00
|
|
|
; CHECK: .local i[[PTR]]{{$}}
|
2016-01-08 02:55:52 +08:00
|
|
|
define void @allocarray_inbounds() {
|
2019-02-23 08:07:39 +08:00
|
|
|
; CHECK: global.get $push[[L3:.+]]=, __stack_pointer{{$}}
|
2020-06-16 06:31:10 +08:00
|
|
|
; CHECK-NEXT: i[[PTR]].const $push[[L4:.+]]=, 32{{$}}
|
|
|
|
; CHECK-NEXT: i[[PTR]].sub $push[[L11:.+]]=, $pop[[L3]], $pop[[L4]]
|
2019-01-08 14:25:55 +08:00
|
|
|
; CHECK-NEXT: local.tee $push[[L10:.+]]=, [[SP:.+]], $pop[[L11]]
|
2019-02-23 08:07:39 +08:00
|
|
|
; CHECK-NEXT: global.set __stack_pointer, $pop[[L10]]{{$}}
|
2016-01-08 02:55:52 +08:00
|
|
|
%r = alloca [5 x i32]
|
|
|
|
; CHECK: i32.const $push[[L3:.+]]=, 1
|
2016-10-07 06:08:28 +08:00
|
|
|
; CHECK-DAG: i32.store 24(${{.+}}), $pop[[L3]]
|
2016-01-08 02:55:52 +08:00
|
|
|
%p = getelementptr inbounds [5 x i32], [5 x i32]* %r, i32 0, i32 0
|
|
|
|
store i32 1, i32* %p
|
|
|
|
; This store should have both the GEP and the FI folded into it.
|
2016-10-07 06:08:28 +08:00
|
|
|
; CHECK-DAG: i32.store 12(${{.+}}), $pop
|
2016-01-26 11:39:31 +08:00
|
|
|
%p2 = getelementptr inbounds [5 x i32], [5 x i32]* %r, i32 0, i32 3
|
2016-01-08 02:55:52 +08:00
|
|
|
store i32 1, i32* %p2
|
2016-02-24 02:13:07 +08:00
|
|
|
call void @ext_func(i64* null);
|
2016-05-25 07:47:41 +08:00
|
|
|
; CHECK: call ext_func
|
2020-06-16 06:31:10 +08:00
|
|
|
; CHECK: i[[PTR]].const $push[[L5:.+]]=, 32{{$}}
|
|
|
|
; CHECK-NEXT: i[[PTR]].add $push[[L7:.+]]=, ${{.+}}, $pop[[L5]]
|
2019-02-23 08:07:39 +08:00
|
|
|
; CHECK-NEXT: global.set __stack_pointer, $pop[[L7]]
|
2016-01-08 02:55:52 +08:00
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
2016-01-20 12:21:16 +08:00
|
|
|
; CHECK-LABEL: dynamic_alloca:
|
2015-12-17 07:21:30 +08:00
|
|
|
define void @dynamic_alloca(i32 %alloc) {
|
2019-02-23 08:07:39 +08:00
|
|
|
; CHECK: global.get $push[[L13:.+]]=, __stack_pointer{{$}}
|
2019-01-08 14:25:55 +08:00
|
|
|
; CHECK-NEXT: local.tee $push[[L12:.+]]=, [[SP:.+]], $pop[[L13]]{{$}}
|
2016-02-23 05:57:17 +08:00
|
|
|
; Target independent codegen bumps the stack pointer.
|
2020-06-16 06:31:10 +08:00
|
|
|
; CHECK: i[[PTR]].sub
|
2016-02-23 05:57:17 +08:00
|
|
|
; Check that SP is written back to memory after decrement
|
2019-02-23 08:07:39 +08:00
|
|
|
; CHECK: global.set __stack_pointer,
|
2016-01-30 02:37:49 +08:00
|
|
|
%r = alloca i32, i32 %alloc
|
|
|
|
; Target-independent codegen also calculates the store addr
|
2019-02-23 08:07:39 +08:00
|
|
|
; CHECK: call ext_func_i32
|
2016-02-24 02:13:07 +08:00
|
|
|
call void @ext_func_i32(i32* %r)
|
2019-02-23 08:07:39 +08:00
|
|
|
; CHECK: global.set __stack_pointer, $pop{{.+}}
|
2016-01-30 02:37:49 +08:00
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
2016-02-24 02:13:07 +08:00
|
|
|
; CHECK-LABEL: dynamic_alloca_redzone:
|
|
|
|
define void @dynamic_alloca_redzone(i32 %alloc) {
|
2019-02-23 08:07:39 +08:00
|
|
|
; CHECK: global.get $push[[L13:.+]]=, __stack_pointer{{$}}
|
2019-01-08 14:25:55 +08:00
|
|
|
; CHECK-NEXT: local.tee $push[[L12:.+]]=, [[SP:.+]], $pop[[L13]]{{$}}
|
2016-02-24 02:13:07 +08:00
|
|
|
; Target independent codegen bumps the stack pointer
|
2020-06-16 06:31:10 +08:00
|
|
|
; CHECK: i[[PTR]].sub
|
2016-02-24 02:13:07 +08:00
|
|
|
%r = alloca i32, i32 %alloc
|
2020-06-16 06:31:10 +08:00
|
|
|
; CHECK-NEXT: local.tee $push[[L8:.+]]=, [[SP2:.+]], $pop
|
|
|
|
; CHECK: local.get $push[[L7:.+]]=, [[SP2]]{{$}}
|
|
|
|
; CHECK-NEXT: i32.const $push[[L6:.+]]=, 0{{$}}
|
|
|
|
; CHECK-NEXT: i32.store 0($pop[[L7]]), $pop[[L6]]{{$}}
|
2016-02-24 02:13:07 +08:00
|
|
|
store i32 0, i32* %r
|
|
|
|
; CHECK-NEXT: return
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
2016-01-30 02:37:49 +08:00
|
|
|
; CHECK-LABEL: dynamic_static_alloca:
|
2016-02-24 02:13:07 +08:00
|
|
|
define void @dynamic_static_alloca(i32 %alloc) noredzone {
|
2016-02-23 05:57:17 +08:00
|
|
|
; Decrement SP in the prolog by the static amount and writeback to memory.
|
2019-02-23 08:07:39 +08:00
|
|
|
; CHECK: global.get $push[[L11:.+]]=, __stack_pointer{{$}}
|
2020-06-16 06:31:10 +08:00
|
|
|
; CHECK-NEXT: i[[PTR]].const $push[[L12:.+]]=, 16
|
|
|
|
; CHECK-NEXT: i[[PTR]].sub $push[[L23:.+]]=, $pop[[L11]], $pop[[L12]]
|
2019-01-08 14:25:55 +08:00
|
|
|
; CHECK-NEXT: local.tee $push[[L22:.+]]=, [[SP:.+]], $pop[[L23]]
|
2019-02-23 08:07:39 +08:00
|
|
|
; CHECK-NEXT: global.set __stack_pointer, $pop[[L22]]
|
2016-09-27 05:18:03 +08:00
|
|
|
|
|
|
|
; Alloc and write to a static alloca
|
2019-01-08 14:25:55 +08:00
|
|
|
; CHECK: local.get $push[[L21:.+]]=, [[SP:.+]]
|
|
|
|
; CHECK-NEXT: local.tee $push[[pushedFP:.+]]=, [[FP:.+]], $pop[[L21]]
|
2016-09-27 05:18:03 +08:00
|
|
|
; CHECK-NEXT: i32.const $push[[L0:.+]]=, 101
|
2016-10-07 06:08:28 +08:00
|
|
|
; CHECK-NEXT: i32.store [[static_offset:.+]]($pop[[pushedFP]]), $pop[[L0]]
|
2016-09-27 05:18:03 +08:00
|
|
|
%static = alloca i32
|
|
|
|
store volatile i32 101, i32* %static
|
|
|
|
|
|
|
|
; Decrement SP in the body by the dynamic amount.
|
2020-06-16 06:31:10 +08:00
|
|
|
; CHECK: i[[PTR]].sub
|
2019-01-08 14:25:55 +08:00
|
|
|
; CHECK: local.tee $push[[L16:.+]]=, [[dynamic_local:.+]], $pop{{.+}}
|
|
|
|
; CHECK: local.tee $push[[L15:.+]]=, [[other:.+]], $pop[[L16]]{{$}}
|
2019-02-23 08:07:39 +08:00
|
|
|
; CHECK: global.set __stack_pointer, $pop[[L15]]{{$}}
|
2016-09-27 05:18:03 +08:00
|
|
|
%dynamic = alloca i32, i32 %alloc
|
|
|
|
|
|
|
|
; Ensure we don't modify the frame pointer after assigning it.
|
|
|
|
; CHECK-NOT: $[[FP]]=
|
|
|
|
|
|
|
|
; Ensure the static address doesn't change after modifying the stack pointer.
|
2019-01-08 14:25:55 +08:00
|
|
|
; CHECK: local.get $push[[L17:.+]]=, [[FP]]
|
2016-09-27 05:18:03 +08:00
|
|
|
; CHECK: i32.const $push[[L7:.+]]=, 102
|
2017-03-01 07:37:04 +08:00
|
|
|
; CHECK-NEXT: i32.store [[static_offset]]($pop[[L17]]), $pop[[L7]]
|
2019-01-08 14:25:55 +08:00
|
|
|
; CHECK-NEXT: local.get $push[[L9:.+]]=, [[dynamic_local]]{{$}}
|
2016-09-27 05:18:03 +08:00
|
|
|
; CHECK-NEXT: i32.const $push[[L8:.+]]=, 103
|
2017-03-01 07:37:04 +08:00
|
|
|
; CHECK-NEXT: i32.store 0($pop[[L9]]), $pop[[L8]]
|
2016-09-27 05:18:03 +08:00
|
|
|
store volatile i32 102, i32* %static
|
|
|
|
store volatile i32 103, i32* %dynamic
|
|
|
|
|
2016-02-23 05:57:17 +08:00
|
|
|
; Decrement SP in the body by the dynamic amount.
|
2020-06-16 06:31:10 +08:00
|
|
|
; CHECK: i[[PTR]].sub
|
2019-01-08 14:25:55 +08:00
|
|
|
; CHECK: local.tee $push{{.+}}=, [[dynamic2_local:.+]], $pop{{.+}}
|
2016-09-27 05:18:03 +08:00
|
|
|
%dynamic.2 = alloca i32, i32 %alloc
|
|
|
|
|
|
|
|
; CHECK-NOT: $[[FP]]=
|
|
|
|
|
|
|
|
; Ensure neither the static nor dynamic address changes after the second
|
|
|
|
; modification of the stack pointer.
|
2019-01-08 14:25:55 +08:00
|
|
|
; CHECK: local.get $push[[L22:.+]]=, [[FP]]
|
2016-09-27 05:18:03 +08:00
|
|
|
; CHECK: i32.const $push[[L9:.+]]=, 104
|
2017-03-01 07:37:04 +08:00
|
|
|
; CHECK-NEXT: i32.store [[static_offset]]($pop[[L22]]), $pop[[L9]]
|
2019-01-08 14:25:55 +08:00
|
|
|
; CHECK-NEXT: local.get $push[[L23:.+]]=, [[dynamic_local]]
|
2016-09-27 05:18:03 +08:00
|
|
|
; CHECK-NEXT: i32.const $push[[L10:.+]]=, 105
|
2017-03-01 07:37:04 +08:00
|
|
|
; CHECK-NEXT: i32.store 0($pop[[L23]]), $pop[[L10]]
|
2019-01-08 14:25:55 +08:00
|
|
|
; CHECK-NEXT: local.get $push[[L23:.+]]=, [[dynamic2_local]]
|
2016-09-27 05:18:03 +08:00
|
|
|
; CHECK-NEXT: i32.const $push[[L11:.+]]=, 106
|
2017-03-01 07:37:04 +08:00
|
|
|
; CHECK-NEXT: i32.store 0($pop[[L23]]), $pop[[L11]]
|
2016-09-27 05:18:03 +08:00
|
|
|
store volatile i32 104, i32* %static
|
|
|
|
store volatile i32 105, i32* %dynamic
|
|
|
|
store volatile i32 106, i32* %dynamic.2
|
|
|
|
|
2016-02-23 05:57:17 +08:00
|
|
|
; Writeback to memory.
|
2019-01-08 14:25:55 +08:00
|
|
|
; CHECK: local.get $push[[L24:.+]]=, [[FP]]{{$}}
|
2020-06-16 06:31:10 +08:00
|
|
|
; CHECK: i[[PTR]].const $push[[L18:.+]]=, 16
|
|
|
|
; CHECK-NEXT: i[[PTR]].add $push[[L19:.+]]=, $pop[[L24]], $pop[[L18]]
|
2019-02-23 08:07:39 +08:00
|
|
|
; CHECK-NEXT: global.set __stack_pointer, $pop[[L19]]
|
2015-12-17 07:21:30 +08:00
|
|
|
ret void
|
|
|
|
}
|
2016-01-31 05:43:08 +08:00
|
|
|
|
2016-10-01 02:02:54 +08:00
|
|
|
declare i8* @llvm.stacksave()
|
|
|
|
declare void @llvm.stackrestore(i8*)
|
|
|
|
|
|
|
|
; CHECK-LABEL: llvm_stack_builtins:
|
|
|
|
define void @llvm_stack_builtins(i32 %alloc) noredzone {
|
2019-02-23 08:07:39 +08:00
|
|
|
; CHECK: global.get $push[[L11:.+]]=, __stack_pointer{{$}}
|
2019-01-08 14:25:55 +08:00
|
|
|
; CHECK-NEXT: local.tee $push[[L10:.+]]=, {{.+}}, $pop[[L11]]
|
|
|
|
; CHECK-NEXT: local.set [[STACK:.+]], $pop[[L10]]
|
2016-10-01 02:02:54 +08:00
|
|
|
%stack = call i8* @llvm.stacksave()
|
|
|
|
|
|
|
|
; Ensure we don't reassign the stacksave local
|
2019-01-08 14:25:55 +08:00
|
|
|
; CHECK-NOT: local.set [[STACK]],
|
2016-10-01 02:02:54 +08:00
|
|
|
%dynamic = alloca i32, i32 %alloc
|
|
|
|
|
2019-01-08 14:25:55 +08:00
|
|
|
; CHECK: local.get $push[[L12:.+]]=, [[STACK]]
|
2019-02-23 08:07:39 +08:00
|
|
|
; CHECK-NEXT: global.set __stack_pointer, $pop[[L12]]
|
2016-10-01 02:02:54 +08:00
|
|
|
call void @llvm.stackrestore(i8* %stack)
|
|
|
|
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
|
|
|
; Not actually using the alloca'd variables exposed an issue with register
|
|
|
|
; stackification, where copying the stack pointer into the frame pointer was
|
|
|
|
; moved after the stack pointer was updated for the dynamic alloca.
|
|
|
|
; CHECK-LABEL: dynamic_alloca_nouse:
|
|
|
|
define void @dynamic_alloca_nouse(i32 %alloc) noredzone {
|
2019-02-23 08:07:39 +08:00
|
|
|
; CHECK: global.get $push[[L11:.+]]=, __stack_pointer{{$}}
|
2019-01-08 14:25:55 +08:00
|
|
|
; CHECK-NEXT: local.tee $push[[L10:.+]]=, {{.+}}, $pop[[L11]]
|
|
|
|
; CHECK-NEXT: local.set [[FP:.+]], $pop[[L10]]
|
2016-10-01 02:02:54 +08:00
|
|
|
%dynamic = alloca i32, i32 %alloc
|
|
|
|
|
2019-01-08 14:25:55 +08:00
|
|
|
; CHECK-NOT: local.set [[FP]],
|
2016-10-01 02:02:54 +08:00
|
|
|
|
2019-01-08 14:25:55 +08:00
|
|
|
; CHECK: local.get $push[[L12:.+]]=, [[FP]]
|
2019-02-23 08:07:39 +08:00
|
|
|
; CHECK-NEXT: global.set __stack_pointer, $pop[[L12]]
|
2016-10-01 02:02:54 +08:00
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
2016-02-17 02:18:36 +08:00
|
|
|
; The use of the alloca in a phi causes a CopyToReg DAG node to be generated,
|
|
|
|
; which has to have special handling because CopyToReg can't have a FI operand
|
|
|
|
; CHECK-LABEL: copytoreg_fi:
|
|
|
|
define void @copytoreg_fi(i1 %cond, i32* %b) {
|
|
|
|
entry:
|
2020-06-16 06:31:10 +08:00
|
|
|
; CHECK: i[[PTR]].const $push[[L1:.+]]=, 16
|
|
|
|
; CHECK-NEXT: i[[PTR]].sub $push[[L3:.+]]=, {{.+}}, $pop[[L1]]
|
2016-02-17 02:18:36 +08:00
|
|
|
%addr = alloca i32
|
2020-06-16 06:31:10 +08:00
|
|
|
; CHECK: i[[PTR]].const $push[[OFF:.+]]=, 12
|
|
|
|
; CHECK-NEXT: i[[PTR]].add $push[[ADDR:.+]]=, $pop[[L3]], $pop[[OFF]]
|
2019-01-08 14:25:55 +08:00
|
|
|
; CHECK-NEXT: local.set [[COPY:.+]], $pop[[ADDR]]
|
2016-02-17 02:18:36 +08:00
|
|
|
br label %body
|
|
|
|
body:
|
|
|
|
%a = phi i32* [%addr, %entry], [%b, %body]
|
|
|
|
store i32 1, i32* %a
|
2019-01-08 14:25:55 +08:00
|
|
|
; CHECK: local.get $push[[L12:.+]]=, [[COPY]]
|
2017-03-01 07:37:04 +08:00
|
|
|
; CHECK: i32.store 0($pop[[L12]]),
|
2016-02-17 02:18:36 +08:00
|
|
|
br i1 %cond, label %body, label %exit
|
|
|
|
exit:
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
2016-02-17 07:48:04 +08:00
|
|
|
declare void @use_i8_star(i8*)
|
|
|
|
declare i8* @llvm.frameaddress(i32)
|
|
|
|
|
|
|
|
; Test __builtin_frame_address(0).
|
|
|
|
; CHECK-LABEL: frameaddress_0:
|
2019-02-23 08:07:39 +08:00
|
|
|
; CHECK: global.get $push[[L3:.+]]=, __stack_pointer{{$}}
|
2019-01-08 14:25:55 +08:00
|
|
|
; CHECK-NEXT: local.tee $push[[L2:.+]]=, [[FP:.+]], $pop[[L3]]{{$}}
|
2019-02-23 08:07:39 +08:00
|
|
|
; CHECK-NEXT: call use_i8_star, $pop[[L2]]
|
2019-01-08 14:25:55 +08:00
|
|
|
; CHECK-NEXT: local.get $push[[L5:.+]]=, [[FP]]
|
2019-02-23 08:07:39 +08:00
|
|
|
; CHECK-NEXT: global.set __stack_pointer, $pop[[L5]]
|
2016-02-17 07:48:04 +08:00
|
|
|
define void @frameaddress_0() {
|
|
|
|
%t = call i8* @llvm.frameaddress(i32 0)
|
|
|
|
call void @use_i8_star(i8* %t)
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
|
|
|
; Test __builtin_frame_address(1).
|
|
|
|
|
|
|
|
; CHECK-LABEL: frameaddress_1:
|
2020-06-16 06:31:10 +08:00
|
|
|
; CHECK: i[[PTR]].const $push0=, 0{{$}}
|
2019-02-23 08:07:39 +08:00
|
|
|
; CHECK-NEXT: call use_i8_star, $pop0{{$}}
|
2016-02-17 07:48:04 +08:00
|
|
|
; CHECK-NEXT: return{{$}}
|
|
|
|
define void @frameaddress_1() {
|
|
|
|
%t = call i8* @llvm.frameaddress(i32 1)
|
|
|
|
call void @use_i8_star(i8* %t)
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
2016-02-21 07:09:44 +08:00
|
|
|
; Test a stack address passed to an inline asm.
|
|
|
|
; CHECK-LABEL: inline_asm:
|
2019-02-23 08:07:39 +08:00
|
|
|
; CHECK: global.get {{.+}}, __stack_pointer{{$}}
|
2016-02-21 07:09:44 +08:00
|
|
|
; CHECK: #APP
|
|
|
|
; CHECK-NEXT: # %{{[0-9]+}}{{$}}
|
|
|
|
; CHECK-NEXT: #NO_APP
|
|
|
|
define void @inline_asm() {
|
|
|
|
%tmp = alloca i8
|
|
|
|
call void asm sideeffect "# %0", "r"(i8* %tmp)
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
2020-11-02 09:29:26 +08:00
|
|
|
; We optimize the format of "frame offset + operand" by folding it, but this is
|
|
|
|
; only possible when that operand is an immediate. In this example it is a
|
|
|
|
; global address, so we should not fold it.
|
|
|
|
; CHECK-LABEL: frame_offset_with_global_address
|
|
|
|
; CHECK: i[[PTR]].const ${{.*}}=, str
|
|
|
|
@str = local_unnamed_addr global [3 x i8] c"abc", align 16
|
|
|
|
define i8 @frame_offset_with_global_address() {
|
|
|
|
%1 = alloca i8, align 4
|
|
|
|
%2 = ptrtoint i8* %1 to i32
|
|
|
|
;; Here @str is a global address and not an immediate, so cannot be folded
|
|
|
|
%3 = getelementptr [3 x i8], [3 x i8]* @str, i32 0, i32 %2
|
|
|
|
%4 = load i8, i8* %3, align 8
|
|
|
|
%5 = and i8 %4, 67
|
|
|
|
ret i8 %5
|
|
|
|
}
|
|
|
|
|
2020-06-16 06:31:10 +08:00
|
|
|
; CHECK: .globaltype __stack_pointer, i[[PTR]]{{$}}
|
2018-11-02 08:45:00 +08:00
|
|
|
|
2016-01-31 05:43:08 +08:00
|
|
|
; TODO: test over-aligned alloca
|