1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc < %s -mtriple=x86_64-apple-darwin | FileCheck %s
3 ; RUN: opt -S -codegenprepare %s -mtriple=x86_64-apple-darwin -o - | FileCheck %s --check-prefix OPT
5 ; Teach CGP to dup returns to enable tail call optimization.
8 define i32 @foo(i32 %x) nounwind ssp {
10 ; CHECK: ## %bb.0: ## %entry
11 ; CHECK-NEXT: ## kill: def $edi killed $edi def $rdi
12 ; CHECK-NEXT: decl %edi
13 ; CHECK-NEXT: cmpl $5, %edi
14 ; CHECK-NEXT: ja LBB0_8
15 ; CHECK-NEXT: ## %bb.1: ## %entry
16 ; CHECK-NEXT: leaq LJTI0_0(%rip), %rax
17 ; CHECK-NEXT: movslq (%rax,%rdi,4), %rcx
18 ; CHECK-NEXT: addq %rax, %rcx
19 ; CHECK-NEXT: jmpq *%rcx
20 ; CHECK-NEXT: LBB0_2: ## %sw.bb
21 ; CHECK-NEXT: jmp _f1 ## TAILCALL
22 ; CHECK-NEXT: LBB0_6: ## %sw.bb7
23 ; CHECK-NEXT: jmp _f5 ## TAILCALL
24 ; CHECK-NEXT: LBB0_4: ## %sw.bb3
25 ; CHECK-NEXT: jmp _f3 ## TAILCALL
26 ; CHECK-NEXT: LBB0_5: ## %sw.bb5
27 ; CHECK-NEXT: jmp _f4 ## TAILCALL
28 ; CHECK-NEXT: LBB0_3: ## %sw.bb1
29 ; CHECK-NEXT: jmp _f2 ## TAILCALL
30 ; CHECK-NEXT: LBB0_7: ## %sw.bb9
31 ; CHECK-NEXT: jmp _f6 ## TAILCALL
32 ; CHECK-NEXT: LBB0_8: ## %return
33 ; CHECK-NEXT: xorl %eax, %eax
35 ; CHECK-NEXT: .p2align 2, 0x90
36 ; CHECK-NEXT: .data_region jt32
37 ; CHECK-NEXT: .set L0_0_set_2, LBB0_2-LJTI0_0
38 ; CHECK-NEXT: .set L0_0_set_3, LBB0_3-LJTI0_0
39 ; CHECK-NEXT: .set L0_0_set_4, LBB0_4-LJTI0_0
40 ; CHECK-NEXT: .set L0_0_set_5, LBB0_5-LJTI0_0
41 ; CHECK-NEXT: .set L0_0_set_6, LBB0_6-LJTI0_0
42 ; CHECK-NEXT: .set L0_0_set_7, LBB0_7-LJTI0_0
43 ; CHECK-NEXT: LJTI0_0:
44 ; CHECK-NEXT: .long L0_0_set_2
45 ; CHECK-NEXT: .long L0_0_set_3
46 ; CHECK-NEXT: .long L0_0_set_4
47 ; CHECK-NEXT: .long L0_0_set_5
48 ; CHECK-NEXT: .long L0_0_set_6
49 ; CHECK-NEXT: .long L0_0_set_7
50 ; CHECK-NEXT: .end_data_region
52 switch i32 %x, label %return [
61 sw.bb: ; preds = %entry
62 %call = tail call i32 @f1() nounwind
65 sw.bb1: ; preds = %entry
66 %call2 = tail call i32 @f2() nounwind
69 sw.bb3: ; preds = %entry
70 %call4 = tail call i32 @f3() nounwind
73 sw.bb5: ; preds = %entry
74 %call6 = tail call i32 @f4() nounwind
77 sw.bb7: ; preds = %entry
78 %call8 = tail call i32 @f5() nounwind
81 sw.bb9: ; preds = %entry
82 %call10 = tail call i32 @f6() nounwind
85 return: ; preds = %entry, %sw.bb9, %sw.bb7, %sw.bb5, %sw.bb3, %sw.bb1, %sw.bb
86 %retval.0 = phi i32 [ %call10, %sw.bb9 ], [ %call8, %sw.bb7 ], [ %call6, %sw.bb5 ], [ %call4, %sw.bb3 ], [ %call2, %sw.bb1 ], [ %call, %sw.bb ], [ 0, %entry ]
105 declare ptr @bar(ptr) uwtable optsize noinline ssp
107 define hidden ptr @thingWithValue(ptr %self) uwtable ssp {
108 ; CHECK-LABEL: thingWithValue:
109 ; CHECK: ## %bb.0: ## %entry
110 ; CHECK-NEXT: xorl %eax, %eax
111 ; CHECK-NEXT: testb %al, %al
112 ; CHECK-NEXT: je _bar ## TAILCALL
113 ; CHECK-NEXT: ## %bb.1: ## %someThingWithValue.exit
116 br i1 undef, label %if.then.i, label %if.else.i
118 if.then.i: ; preds = %entry
119 br label %someThingWithValue.exit
121 if.else.i: ; preds = %entry
122 %call4.i = tail call ptr @bar(ptr undef) optsize
123 br label %someThingWithValue.exit
125 someThingWithValue.exit: ; preds = %if.else.i, %if.then.i
126 %retval.0.in.i = phi ptr [ undef, %if.then.i ], [ %call4.i, %if.else.i ]
127 ret ptr %retval.0.in.i
131 ; Correctly handle zext returns.
132 declare zeroext i1 @foo_i1()
134 define zeroext i1 @zext_i1(i1 %k) {
135 ; CHECK-LABEL: zext_i1:
136 ; CHECK: ## %bb.0: ## %entry
137 ; CHECK-NEXT: testb $1, %dil
138 ; CHECK-NEXT: je _foo_i1 ## TAILCALL
139 ; CHECK-NEXT: ## %bb.1: ## %land.end
140 ; CHECK-NEXT: xorl %eax, %eax
143 br i1 %k, label %land.end, label %land.rhs
145 land.rhs: ; preds = %entry
146 %call1 = tail call zeroext i1 @foo_i1()
149 land.end: ; preds = %entry, %land.rhs
150 %0 = phi i1 [ false, %entry ], [ %call1, %land.rhs ]
154 ; We need to look through bitcasts when looking for tail calls in phi incoming
156 declare ptr @g_ret32()
157 define ptr @f_ret8(ptr %obj) nounwind {
158 ; OPT-LABEL: @f_ret8(
160 ; OPT-NEXT: [[CMP:%.*]] = icmp eq ptr [[OBJ:%.*]], null
161 ; OPT-NEXT: br i1 [[CMP]], label [[RETURN:%.*]], label [[IF_THEN:%.*]]
163 ; OPT-NEXT: [[PTR:%.*]] = tail call ptr @g_ret32()
164 ; OPT-NEXT: ret ptr [[PTR]]
166 ; OPT-NEXT: ret ptr [[OBJ]]
168 ; CHECK-LABEL: f_ret8:
169 ; CHECK: ## %bb.0: ## %entry
170 ; CHECK-NEXT: testq %rdi, %rdi
171 ; CHECK-NEXT: jne _g_ret32 ## TAILCALL
172 ; CHECK-NEXT: ## %bb.1: ## %return
173 ; CHECK-NEXT: movq %rdi, %rax
176 %cmp = icmp eq ptr %obj, null
177 br i1 %cmp, label %return, label %if.then
180 %ptr = tail call ptr @g_ret32()
184 %retval = phi ptr [ %ptr, %if.then ], [ %obj, %entry ]