2015-12-12 07:49:46 +08:00
|
|
|
; RUN: llc < %s -asm-verbose=false | FileCheck %s
|
|
|
|
; RUN: llc < %s -asm-verbose=false -fast-isel | FileCheck %s
|
|
|
|
|
|
|
|
|
2016-01-07 11:19:23 +08:00
|
|
|
target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
|
2015-12-12 07:49:46 +08:00
|
|
|
target triple = "wasm32-unknown-unknown"
|
|
|
|
|
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.
|
2016-02-21 05:46:50 +08:00
|
|
|
; CHECK: .local i32{{$}}
|
2016-02-24 02:13:07 +08:00
|
|
|
define void @alloca32() noredzone {
|
2016-02-21 05:46:50 +08:00
|
|
|
; CHECK: i32.const $push[[L1:.+]]=, __stack_pointer{{$}}
|
|
|
|
; CHECK-NEXT: i32.load $push[[L2:.+]]=, 0($pop[[L1]])
|
|
|
|
; CHECK-NEXT: i32.const $push[[L3:.+]]=, 16
|
|
|
|
; CHECK-NEXT: i32.sub [[SP:.+]]=, $pop[[L2]], $pop[[L3]]
|
|
|
|
; CHECK-NEXT: i32.const $push[[L4:.+]]=, __stack_pointer{{$}}
|
2016-02-21 11:27:22 +08:00
|
|
|
; CHECK-NEXT: i32.store $discard=, 0($pop[[L4]]), [[SP]]
|
2015-12-12 07:49:46 +08:00
|
|
|
%retval = alloca i32
|
2016-02-21 05:46:50 +08:00
|
|
|
; CHECK: i32.const $push[[L0:.+]]=, 0
|
|
|
|
; CHECK: i32.store {{.*}}=, 12([[SP]]), $pop[[L0]]
|
2015-12-12 07:49:46 +08:00
|
|
|
store i32 0, i32* %retval
|
2016-03-18 01:00:29 +08:00
|
|
|
; CHECK: i32.const $push[[L6:.+]]=, __stack_pointer
|
|
|
|
; CHECK-NEXT: i32.const $push[[L5:.+]]=, 16
|
|
|
|
; CHECK-NEXT: i32.add $push[[L7:.+]]=, [[SP]], $pop[[L5]]
|
|
|
|
; CHECK-NEXT: i32.store $discard=, 0($pop[[L6]]), $pop[[L7]]
|
2015-12-12 07:49:46 +08:00
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
|
|
|
; CHECK-LABEL: alloca3264:
|
2016-02-21 05:46:50 +08:00
|
|
|
; CHECK: .local i32{{$}}
|
2015-12-12 07:49:46 +08:00
|
|
|
define void @alloca3264() {
|
2016-02-21 05:46:50 +08:00
|
|
|
; CHECK: i32.const $push[[L1:.+]]=, __stack_pointer
|
|
|
|
; CHECK-NEXT: i32.load $push[[L2:.+]]=, 0($pop[[L1]])
|
|
|
|
; CHECK-NEXT: i32.const $push[[L3:.+]]=, 16
|
|
|
|
; CHECK-NEXT: i32.sub [[SP:.+]]=, $pop[[L2]], $pop[[L3]]
|
2015-12-12 07:49:46 +08:00
|
|
|
%r1 = alloca i32
|
|
|
|
%r2 = alloca double
|
2016-02-24 02:13:07 +08:00
|
|
|
; CHECK-NEXT: i32.const $push[[L3:.+]]=, 0
|
|
|
|
; CHECK-NEXT: i32.store {{.*}}=, 12([[SP]]), $pop[[L3]]
|
2015-12-12 07:49:46 +08:00
|
|
|
store i32 0, i32* %r1
|
2016-02-24 02:13:07 +08:00
|
|
|
; CHECK-NEXT: i64.const $push[[L0:.+]]=, 0
|
|
|
|
; CHECK-NEXT: i64.store {{.*}}=, 0([[SP]]), $pop[[L0]]
|
2015-12-12 07:49:46 +08:00
|
|
|
store double 0.0, double* %r2
|
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:
|
2016-03-18 01:00:29 +08:00
|
|
|
; CHECK: .local i32{{$}}
|
2015-12-12 07:49:46 +08:00
|
|
|
define void @allocarray() {
|
2016-02-21 05:46:50 +08:00
|
|
|
; CHECK: i32.const $push[[L1:.+]]=, __stack_pointer
|
|
|
|
; CHECK-NEXT: i32.load $push[[L2:.+]]=, 0($pop[[L1]])
|
2016-02-24 02:13:07 +08:00
|
|
|
; CHECK-NEXT: i32.const $push[[L3:.+]]=, 144{{$}}
|
2016-02-21 05:46:50 +08:00
|
|
|
; CHECK-NEXT: i32.sub [[SP:.+]]=, $pop[[L2]], $pop[[L3]]
|
|
|
|
; CHECK-NEXT: i32.const $push[[L4:.+]]=, __stack_pointer{{$}}
|
2016-02-21 11:27:22 +08:00
|
|
|
; CHECK-NEXT: i32.store $discard=, 0($pop[[L4]]), [[SP]]
|
2016-02-24 02:13:07 +08:00
|
|
|
%r = alloca [33 x i32]
|
2016-01-20 12:21:16 +08:00
|
|
|
|
2016-03-18 01:00:29 +08:00
|
|
|
; CHECK-NEXT: i32.const $push[[L5:.+]]=, 12
|
|
|
|
; CHECK-NEXT: i32.add $push[[L7:.+]]=, [[SP]], $pop[[L5]]
|
2016-01-26 11:39:31 +08:00
|
|
|
; CHECK-NEXT: i32.const $push[[L4:.+]]=, 12
|
2016-03-18 01:00:29 +08:00
|
|
|
; CHECK-NEXT: i32.add $push[[L6:.+]]=, $pop[[L7]], $pop[[L4]]
|
2016-01-20 12:21:16 +08:00
|
|
|
; CHECK-NEXT: i32.const $push[[L9:.+]]=, 1{{$}}
|
|
|
|
; CHECK-NEXT: i32.store $push[[L10:.+]]=, 12([[SP]]), $pop[[L9]]{{$}}
|
|
|
|
; CHECK-NEXT: i32.store $discard=, 0($pop3), $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
|
|
|
|
2016-03-18 01:00:29 +08:00
|
|
|
; CHECK: i32.const $push[[L12:.+]]=, __stack_pointer
|
|
|
|
; CHECK-NEXT: i32.const $push[[L11:.+]]=, 144
|
|
|
|
; CHECK-NEXT: i32.add $push[[L13:.+]]=, [[SP]], $pop[[L11]]
|
|
|
|
; CHECK-NEXT: i32.store $discard=, 0($pop[[L12]]), $pop[[L13]]
|
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) {
|
2016-02-21 05:46:50 +08:00
|
|
|
; CHECK: i32.const $push[[L1:.+]]=, 48
|
|
|
|
; CHECK-NEXT: i32.sub [[SP:.+]]=, {{.+}}, $pop[[L1]]
|
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
|
2016-03-18 01:00:29 +08:00
|
|
|
; CHECK: i32.const $push[[OFF:.+]]=, 8
|
|
|
|
; CHECK-NEXT: i32.add $push[[ARG1:.+]]=, [[SP]], $pop[[OFF]]
|
|
|
|
; CHECK-NEXT: call ext_func@FUNCTION, $pop[[ARG1]]
|
2016-01-27 06:47:43 +08:00
|
|
|
call void @ext_func(i64* %r)
|
|
|
|
; %r2 is at SP+0, no add needed
|
|
|
|
; CHECK-NEXT: call ext_func@FUNCTION, [[SP]]
|
|
|
|
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
|
2016-03-18 01:00:29 +08:00
|
|
|
; CHECK: i32.const $push[[OFF:.+]]=, 16
|
|
|
|
; CHECK-NEXT: i32.add $push[[VAL:.+]]=, [[SP]], $pop[[OFF]]
|
|
|
|
; CHECK-NEXT: i32.store {{.*}}=, 0($0), $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:
|
2016-02-21 05:46:50 +08:00
|
|
|
; CHECK: .local i32{{$}}
|
2016-01-08 02:55:52 +08:00
|
|
|
define void @allocarray_inbounds() {
|
2016-02-21 05:46:50 +08:00
|
|
|
; CHECK: i32.const $push[[L1:.+]]=, __stack_pointer
|
|
|
|
; CHECK-NEXT: i32.load $push[[L2:.+]]=, 0($pop[[L1]])
|
|
|
|
; CHECK-NEXT: i32.const $push[[L3:.+]]=, 32{{$}}
|
|
|
|
; CHECK-NEXT: i32.sub [[SP:.+]]=, $pop[[L2]], $pop[[L3]]
|
2016-01-08 02:55:52 +08:00
|
|
|
%r = alloca [5 x i32]
|
|
|
|
; CHECK: i32.const $push[[L3:.+]]=, 1
|
|
|
|
; CHECK: i32.store {{.*}}=, 12([[SP]]), $pop[[L3]]
|
|
|
|
%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-01-26 11:39:31 +08:00
|
|
|
; CHECK-NEXT: i32.store {{.*}}=, 24([[SP]]), $pop
|
|
|
|
%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-03-18 01:00:29 +08:00
|
|
|
; CHECK: i32.const $push[[L6:.+]]=, __stack_pointer
|
|
|
|
; CHECK-NEXT: i32.const $push[[L5:.+]]=, 32
|
|
|
|
; CHECK-NEXT: i32.add $push[[L7:.+]]=, [[SP]], $pop[[L5]]
|
|
|
|
; CHECK-NEXT: i32.store $discard=, 0($pop[[L6]]), $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) {
|
2016-02-21 05:46:50 +08:00
|
|
|
; CHECK: i32.const $push[[L1:.+]]=, __stack_pointer
|
|
|
|
; CHECK-NEXT: i32.load [[SP:.+]]=, 0($pop[[L1]])
|
2016-01-30 02:37:49 +08:00
|
|
|
; CHECK-NEXT: copy_local [[FP:.+]]=, [[SP]]
|
2016-02-23 05:57:17 +08:00
|
|
|
; Target independent codegen bumps the stack pointer.
|
|
|
|
; CHECK: i32.sub
|
|
|
|
; CHECK-NEXT: copy_local [[SP]]=,
|
|
|
|
; Check that SP is written back to memory after decrement
|
|
|
|
; CHECK-NEXT: i32.const $push[[L4:.+]]=, __stack_pointer{{$}}
|
2016-02-21 11:27:22 +08:00
|
|
|
; CHECK-NEXT: i32.store $discard=, 0($pop[[L4]]), [[SP]]
|
2016-01-30 02:37:49 +08:00
|
|
|
%r = alloca i32, i32 %alloc
|
|
|
|
; Target-independent codegen also calculates the store addr
|
2016-02-24 02:13:07 +08:00
|
|
|
; CHECK: call ext_func_i32@FUNCTION
|
|
|
|
call void @ext_func_i32(i32* %r)
|
2016-02-21 05:46:50 +08:00
|
|
|
; CHECK: i32.const $push[[L3:.+]]=, __stack_pointer
|
2016-03-18 01:00:29 +08:00
|
|
|
; CHECK-NEXT: i32.store $discard=, 0($pop[[L3]]), [[FP]]
|
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) {
|
|
|
|
; CHECK: i32.const $push[[L1:.+]]=, __stack_pointer
|
|
|
|
; CHECK-NEXT: i32.load [[SP:.+]]=, 0($pop[[L1]])
|
|
|
|
; CHECK-NEXT: copy_local [[FP:.+]]=, [[SP]]
|
|
|
|
; Target independent codegen bumps the stack pointer
|
|
|
|
; CHECK: i32.sub [[R:.+]]=,
|
|
|
|
; CHECK-NEXT: copy_local [[SP]]=, [[R]]
|
|
|
|
%r = alloca i32, i32 %alloc
|
|
|
|
; check-next here asserts that SP is not written back.
|
|
|
|
; CHECK-NEXT: i32.const $push[[ZERO:.+]]=, 0
|
|
|
|
; CHECK-NEXT: i32.store $discard=, 0([[R]]), $pop[[ZERO]]
|
|
|
|
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.
|
2016-02-21 05:46:50 +08:00
|
|
|
; CHECK: i32.const $push[[L1:.+]]=, __stack_pointer
|
|
|
|
; CHECK-NEXT: i32.load $push[[L2:.+]]=, 0($pop[[L1]])
|
|
|
|
; CHECK-NEXT: i32.const $push[[L3:.+]]=, 16
|
|
|
|
; CHECK-NEXT: i32.sub [[SP:.+]]=, $pop[[L2]], $pop[[L3]]
|
2016-01-30 02:37:49 +08:00
|
|
|
; CHECK-NEXT: copy_local [[FP:.+]]=, [[SP]]
|
2016-02-21 05:46:50 +08:00
|
|
|
; CHECK-NEXT: i32.const $push[[L4:.+]]=, __stack_pointer
|
|
|
|
; CHECK-NEXT: i32.store {{.*}}=, 0($pop[[L4]]), [[SP]]
|
2016-02-23 05:57:17 +08:00
|
|
|
; Decrement SP in the body by the dynamic amount.
|
|
|
|
; CHECK: i32.sub
|
|
|
|
; CHECK: copy_local [[SP]]=,
|
|
|
|
; Writeback to memory.
|
|
|
|
; CHECK-NEXT: i32.const $push[[L4:.+]]=, __stack_pointer
|
|
|
|
; CHECK-NEXT: i32.store {{.*}}=, 0($pop[[L4]]), [[SP]]
|
2016-01-30 02:37:49 +08:00
|
|
|
%r1 = alloca i32
|
|
|
|
%r = alloca i32, i32 %alloc
|
|
|
|
store i32 0, i32* %r
|
2016-03-18 01:00:29 +08:00
|
|
|
; CHECK: i32.const $push[[L6:.+]]=, __stack_pointer
|
|
|
|
; CHECK-NEXT: i32.const $push[[L5:.+]]=, 16
|
|
|
|
; CHECK-NEXT: i32.add $push[[L7:.+]]=, [[FP]], $pop[[L5]]
|
|
|
|
; CHECK-NEXT: i32.store $discard=, 0($pop[[L6]]), $pop[[L7]]
|
2015-12-17 07:21:30 +08:00
|
|
|
ret void
|
|
|
|
}
|
2016-01-31 05:43:08 +08:00
|
|
|
|
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:
|
2016-02-21 05:46:50 +08:00
|
|
|
; CHECK: i32.const $push[[L1:.+]]=, 16
|
|
|
|
; CHECK-NEXT: i32.sub [[SP:.+]]=, {{.+}}, $pop[[L1]]
|
2016-02-17 02:18:36 +08:00
|
|
|
%addr = alloca i32
|
2016-03-18 01:00:29 +08:00
|
|
|
; CHECK: i32.const $push[[OFF:.+]]=, 12
|
|
|
|
; CHECK-NEXT: i32.add $push[[ADDR:.+]]=, [[SP]], $pop[[OFF]]
|
|
|
|
; CHECK-NEXT: copy_local [[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
|
|
|
|
; CHECK: i32.store {{.*}}, 0([[COPY]]),
|
|
|
|
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:
|
2016-02-21 05:46:50 +08:00
|
|
|
; CHECK: i32.const $push[[L1:.+]]=, __stack_pointer
|
|
|
|
; CHECK-NEXT: i32.load [[SP:.+]]=, 0($pop[[L1]])
|
|
|
|
; CHECK-NEXT: copy_local [[FP:.+]]=, [[SP]]
|
|
|
|
; CHECK-NEXT: call use_i8_star@FUNCTION, [[FP]]
|
2016-02-24 02:13:07 +08:00
|
|
|
; CHEC K-NEXT: i32.const $push[[L6:.+]]=, __stack_pointer
|
|
|
|
; CHEC K-NEXT: i32.store [[SP]]=, 0($pop[[L6]]), [[FP]]
|
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:
|
|
|
|
; CHECK-NEXT: i32.const $push0=, 0{{$}}
|
|
|
|
; CHECK-NEXT: call use_i8_star@FUNCTION, $pop0{{$}}
|
|
|
|
; 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:
|
|
|
|
; CHECK: __stack_pointer
|
|
|
|
; 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
|
|
|
|
}
|
|
|
|
|
2016-01-31 05:43:08 +08:00
|
|
|
; TODO: test over-aligned alloca
|