Use unsigned comparison in segmented stack prologue.
[oota-llvm.git] / test / CodeGen / X86 / segmented-stacks.ll
1 ; RUN: llc < %s -mtriple=i686-linux -segmented-stacks -verify-machineinstrs | FileCheck %s -check-prefix=X32
2 ; RUN: llc < %s -mtriple=x86_64-linux  -segmented-stacks -verify-machineinstrs | FileCheck %s -check-prefix=X64
3
4 ; We used to crash with filetype=obj
5 ; RUN: llc < %s -mtriple=i686-linux -segmented-stacks -filetype=obj
6 ; RUN: llc < %s -mtriple=x86_64-linux -segmented-stacks -filetype=obj
7
8 ; Just to prevent the alloca from being optimized away
9 declare void @dummy_use(i32*, i32)
10
11 define i32 @test_basic(i32 %l) {
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
17 true:
18         ret i32 0
19
20 false:
21         %newlen = sub i32 %l, 1
22         %retvalue = call i32 @test_basic(i32 %newlen)
23         ret i32 %retvalue
24
25 ; X32:      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-NEXT: 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:      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
57 ; X64-NEXT: subq %rax, %rdi
58 ; X64-NEXT: cmpq %rdi, %fs:112
59
60 ; X64:      movq %rdi, %rsp
61
62 ; X64:      movq %rax, %rdi
63 ; X64-NEXT: callq __morestack_allocate_stack_space
64 ; X64-NEXT: movq %rax, %rdi
65
66 }
67
68 define i32 @test_nested(i32 * nest %closure, i32 %other) {
69        %addend = load i32 * %closure
70        %result = add i32 %other, %addend
71        ret i32 %result
72
73 ; X32:      cmpl %gs:48, %esp
74 ; X32-NEXT: ja      .LBB1_2
75
76 ; X32:      pushl $4
77 ; X32-NEXT: pushl $0
78 ; X32-NEXT: calll __morestack
79 ; X32-NEXT: ret
80
81 ; X64:      cmpq %fs:112, %rsp
82 ; X64-NEXT: ja      .LBB1_2
83
84 ; X64:      movq %r10, %rax
85 ; X64-NEXT: movabsq $0, %r10
86 ; X64-NEXT: movabsq $0, %r11
87 ; X64-NEXT: callq __morestack
88 ; X64-NEXT: ret
89 ; X64-NEXT: movq %rax, %r10
90
91 }
92
93 define void @test_large() {
94         %mem = alloca i32, i32 10000
95         call void @dummy_use (i32* %mem, i32 0)
96         ret void
97
98 ; X32:      leal -40012(%esp), %ecx
99 ; X32-NEXT: cmpl %gs:48, %ecx
100 ; X32-NEXT: ja      .LBB2_2
101
102 ; X32:      pushl $0
103 ; X32-NEXT: pushl $40012
104 ; X32-NEXT: calll __morestack
105 ; X32-NEXT: ret
106
107 ; X64:      leaq -40008(%rsp), %r11
108 ; X64-NEXT: cmpq %fs:112, %r11
109 ; X64-NEXT: ja      .LBB2_2
110
111 ; X64:      movabsq $40008, %r10
112 ; X64-NEXT: movabsq $0, %r11
113 ; X64-NEXT: callq __morestack
114 ; X64-NEXT: ret
115
116 }