1; RUN: llc < %s -mcpu=generic -mtriple=i686-linux -verify-machineinstrs | FileCheck %s -check-prefix=X32
2; RUN: llc < %s -mcpu=generic -mtriple=x86_64-linux -verify-machineinstrs | FileCheck %s -check-prefix=X64
3; RUN: llc < %s -mcpu=generic -mtriple=x86_64-linux-gnux32 -verify-machineinstrs | FileCheck %s -check-prefix=X32ABI
4; RUN: llc < %s -mcpu=generic -mtriple=i686-linux -filetype=obj
5; RUN: llc < %s -mcpu=generic -mtriple=x86_64-linux -filetype=obj
6; RUN: llc < %s -mcpu=generic -mtriple=x86_64-linux-gnux32 -filetype=obj
7
8; Just to prevent the alloca from being optimized away
9declare void @dummy_use(i32*, i32)
10
11define i32 @test_basic(i32 %l) #0 {
12        %mem = alloca i32, i32 %l
13        call void @dummy_use (i32* %mem, i32 %l)
14        %terminate = icmp eq i32 %l, 0
15        br i1 %terminate, label %true, label %false
16
17true:
18        ret i32 0
19
20false:
21        %newlen = sub i32 %l, 1
22        %retvalue = call i32 @test_basic(i32 %newlen)
23        ret i32 %retvalue
24
25; X32-LABEL:      test_basic:
26
27; X32:      cmpl %gs:48, %esp
28; X32-NEXT: ja      .LBB0_2
29
30; X32:      pushl $4
31; X32-NEXT: pushl $12
32; X32-NEXT: calll __morestack
33; X32-NEXT: ret
34
35; X32:      movl %esp, %eax
36; X32:      subl %ecx, %eax
37; X32-NEXT: cmpl %eax, %gs:48
38
39; X32:      movl %eax, %esp
40
41; X32:      subl $12, %esp
42; X32-NEXT: pushl %ecx
43; X32-NEXT: calll __morestack_allocate_stack_space
44; X32-NEXT: addl $16, %esp
45
46; X64-LABEL:      test_basic:
47
48; X64:      cmpq %fs:112, %rsp
49; X64-NEXT: ja      .LBB0_2
50
51; X64:      movabsq $24, %r10
52; X64-NEXT: movabsq $0, %r11
53; X64-NEXT: callq __morestack
54; X64-NEXT: ret
55
56; X64:      movq %rsp, %[[RDI:rdi|rax]]
57; X64:      subq %{{.*}}, %[[RDI]]
58; X64-NEXT: cmpq %[[RDI]], %fs:112
59
60; X64:      movq %[[RDI]], %rsp
61
62; X64:      movq %{{.*}}, %rdi
63; X64-NEXT: callq __morestack_allocate_stack_space
64; X64:      movq %rax, %rdi
65
66; X32ABI-LABEL:      test_basic:
67
68; X32ABI:      cmpl %fs:64, %esp
69; X32ABI-NEXT: ja      .LBB0_2
70
71; X32ABI:      movl $24, %r10d
72; X32ABI-NEXT: movl $0, %r11d
73; X32ABI-NEXT: callq __morestack
74; X32ABI-NEXT: ret
75
76; X32ABI:      movl %esp, %[[EDI:edi|eax]]
77; X32ABI:      subl %{{.*}}, %[[EDI]]
78; X32ABI-NEXT: cmpl %[[EDI]], %fs:64
79
80; X32ABI:      movl %[[EDI]], %esp
81
82; X32ABI:      movl %{{.*}}, %edi
83; X32ABI-NEXT: callq __morestack_allocate_stack_space
84; X32ABI:      movl %eax, %edi
85
86}
87
88attributes #0 = { "split-stack" }
89