Add a triple to switch.ll test.
[oota-llvm.git] / test / CodeGen / X86 / win64_eh.ll
1 ; RUN: llc < %s -O0 -mattr=sse2 -mtriple=x86_64-pc-windows-itanium | FileCheck %s -check-prefix=WIN64 -check-prefix=NORM
2 ; RUN: llc < %s -O0 -mattr=sse2 -mtriple=x86_64-pc-mingw32 | FileCheck %s -check-prefix=WIN64 -check-prefix=NORM
3 ; RUN: llc < %s -O0 -mattr=sse2 -mtriple=x86_64-pc-mingw32 -mcpu=atom | FileCheck %s -check-prefix=WIN64 -check-prefix=ATOM
4
5 ; Check function without prolog
6 define void @foo0() uwtable {
7 entry:
8   ret void
9 }
10 ; WIN64-LABEL: foo0:
11 ; WIN64: .seh_proc foo0
12 ; WIN64: .seh_endprologue
13 ; WIN64: ret
14 ; WIN64: .seh_endproc
15
16 ; Checks a small stack allocation
17 define void @foo1() uwtable {
18 entry:
19   %baz = alloca [2000 x i16], align 2
20   ret void
21 }
22 ; WIN64-LABEL: foo1:
23 ; WIN64: .seh_proc foo1
24 ; NORM:  subq $4000, %rsp
25 ; ATOM:  leaq -4000(%rsp), %rsp
26 ; WIN64: .seh_stackalloc 4000
27 ; WIN64: .seh_endprologue
28 ; WIN64: addq $4000, %rsp
29 ; WIN64: ret
30 ; WIN64: .seh_endproc
31
32 ; Checks a stack allocation requiring call to __chkstk/___chkstk_ms
33 define void @foo2() uwtable {
34 entry:
35   %baz = alloca [4000 x i16], align 2
36   ret void
37 }
38 ; WIN64-LABEL: foo2:
39 ; WIN64: .seh_proc foo2
40 ; WIN64: movl $8000, %eax
41 ; WIN64: callq {{__chkstk|___chkstk_ms}}
42 ; WIN64: subq %rax, %rsp
43 ; WIN64: .seh_stackalloc 8000
44 ; WIN64: .seh_endprologue
45 ; WIN64: addq $8000, %rsp
46 ; WIN64: ret
47 ; WIN64: .seh_endproc
48
49
50 ; Checks stack push
51 define i32 @foo3(i32 %f_arg, i32 %e_arg, i32 %d_arg, i32 %c_arg, i32 %b_arg, i32 %a_arg) uwtable {
52 entry:
53   %a = alloca i32
54   %b = alloca i32
55   %c = alloca i32
56   %d = alloca i32
57   %e = alloca i32
58   %f = alloca i32
59   store i32 %a_arg, i32* %a
60   store i32 %b_arg, i32* %b
61   store i32 %c_arg, i32* %c
62   store i32 %d_arg, i32* %d
63   store i32 %e_arg, i32* %e
64   store i32 %f_arg, i32* %f
65   %tmp = load i32, i32* %a
66   %tmp1 = mul i32 %tmp, 2
67   %tmp2 = load i32, i32* %b
68   %tmp3 = mul i32 %tmp2, 3
69   %tmp4 = add i32 %tmp1, %tmp3
70   %tmp5 = load i32, i32* %c
71   %tmp6 = mul i32 %tmp5, 5
72   %tmp7 = add i32 %tmp4, %tmp6
73   %tmp8 = load i32, i32* %d
74   %tmp9 = mul i32 %tmp8, 7
75   %tmp10 = add i32 %tmp7, %tmp9
76   %tmp11 = load i32, i32* %e
77   %tmp12 = mul i32 %tmp11, 11
78   %tmp13 = add i32 %tmp10, %tmp12
79   %tmp14 = load i32, i32* %f
80   %tmp15 = mul i32 %tmp14, 13
81   %tmp16 = add i32 %tmp13, %tmp15
82   ret i32 %tmp16
83 }
84 ; WIN64-LABEL: foo3:
85 ; WIN64: .seh_proc foo3
86 ; WIN64: pushq %rsi
87 ; WIN64: .seh_pushreg 6
88 ; NORM:  subq $24, %rsp
89 ; ATOM:  leaq -24(%rsp), %rsp
90 ; WIN64: .seh_stackalloc 24
91 ; WIN64: .seh_endprologue
92 ; WIN64: addq $24, %rsp
93 ; WIN64: popq %rsi
94 ; WIN64: ret
95 ; WIN64: .seh_endproc
96
97
98 ; Check emission of eh handler and handler data
99 declare i32 @_d_eh_personality(i32, i32, i64, i8*, i8*)
100 declare void @_d_eh_resume_unwind(i8*)
101
102 declare i32 @bar()
103
104 define i32 @foo4() #0 {
105 entry:
106   %step = alloca i32, align 4
107   store i32 0, i32* %step
108   %tmp = load i32, i32* %step
109
110   %tmp1 = invoke i32 @bar()
111           to label %finally unwind label %landingpad
112
113 finally:
114   store i32 1, i32* %step
115   br label %endtryfinally
116
117 landingpad:
118   %landing_pad = landingpad { i8*, i32 } personality i32 (i32, i32, i64, i8*, i8*)* @_d_eh_personality
119           cleanup
120   %tmp3 = extractvalue { i8*, i32 } %landing_pad, 0
121   store i32 2, i32* %step
122   call void @_d_eh_resume_unwind(i8* %tmp3)
123   unreachable
124
125 endtryfinally:
126   %tmp10 = load i32, i32* %step
127   ret i32 %tmp10
128 }
129 ; WIN64-LABEL: foo4:
130 ; WIN64: .seh_proc foo4
131 ; WIN64: .seh_handler _d_eh_personality, @unwind, @except
132 ; NORM:  subq $56, %rsp
133 ; ATOM:  leaq -56(%rsp), %rsp
134 ; WIN64: .seh_stackalloc 56
135 ; WIN64: .seh_endprologue
136 ; WIN64: addq $56, %rsp
137 ; WIN64: ret
138 ; WIN64: .seh_handlerdata
139 ; WIN64: .seh_endproc
140
141
142 ; Check stack re-alignment and xmm spilling
143 define void @foo5() uwtable {
144 entry:
145   %s = alloca i32, align 64
146   call void asm sideeffect "", "~{rbx},~{rdi},~{xmm6},~{xmm7}"()
147   ret void
148 }
149 ; WIN64-LABEL: foo5:
150 ; WIN64: .seh_proc foo5
151 ; WIN64: pushq %rbp
152 ; WIN64: .seh_pushreg 5
153 ; WIN64: pushq %rdi
154 ; WIN64: .seh_pushreg 7
155 ; WIN64: pushq %rbx
156 ; WIN64: .seh_pushreg 3
157 ; NORM:  subq  $96, %rsp
158 ; ATOM:  leaq -96(%rsp), %rsp
159 ; WIN64: .seh_stackalloc 96
160 ; WIN64: leaq  96(%rsp), %rbp
161 ; WIN64: .seh_setframe 5, 96
162 ; WIN64: movaps  %xmm7, -16(%rbp)        # 16-byte Spill
163 ; WIN64: .seh_savexmm 7, 80
164 ; WIN64: movaps  %xmm6, -32(%rbp)        # 16-byte Spill
165 ; WIN64: .seh_savexmm 6, 64
166 ; WIN64: .seh_endprologue
167 ; WIN64: andq  $-64, %rsp
168 ; WIN64: movaps  -32(%rbp), %xmm6        # 16-byte Reload
169 ; WIN64: movaps  -16(%rbp), %xmm7        # 16-byte Reload
170 ; WIN64: movq  %rbp, %rsp
171 ; WIN64: popq  %rbx
172 ; WIN64: popq  %rdi
173 ; WIN64: popq  %rbp
174 ; WIN64: retq
175 ; WIN64: .seh_endproc