1 ; NOTE: Assertions have been autogenerated by utils/update_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 {
11 switch i32 %x, label %return [
20 sw.bb: ; preds = %entry
22 %call = tail call i32 @f1() nounwind
25 sw.bb1: ; preds = %entry
27 %call2 = tail call i32 @f2() nounwind
30 sw.bb3: ; preds = %entry
32 %call4 = tail call i32 @f3() nounwind
35 sw.bb5: ; preds = %entry
37 %call6 = tail call i32 @f4() nounwind
40 sw.bb7: ; preds = %entry
42 %call8 = tail call i32 @f5() nounwind
45 sw.bb9: ; preds = %entry
47 %call10 = tail call i32 @f6() nounwind
50 return: ; preds = %entry, %sw.bb9, %sw.bb7, %sw.bb5, %sw.bb3, %sw.bb1, %sw.bb
51 %retval.0 = phi i32 [ %call10, %sw.bb9 ], [ %call8, %sw.bb7 ], [ %call6, %sw.bb5 ], [ %call4, %sw.bb3 ], [ %call2, %sw.bb1 ], [ %call, %sw.bb ], [ 0, %entry ]
70 declare i8* @bar(i8*) uwtable optsize noinline ssp
72 define hidden %0* @thingWithValue(i8* %self) uwtable ssp {
74 ; CHECK-LABEL: thingWithValue:
76 br i1 undef, label %if.then.i, label %if.else.i
78 if.then.i: ; preds = %entry
79 br label %someThingWithValue.exit
81 if.else.i: ; preds = %entry
82 %call4.i = tail call i8* @bar(i8* undef) optsize
83 br label %someThingWithValue.exit
85 someThingWithValue.exit: ; preds = %if.else.i, %if.then.i
86 %retval.0.in.i = phi i8* [ undef, %if.then.i ], [ %call4.i, %if.else.i ]
87 %retval.0.i = bitcast i8* %retval.0.in.i to %0*
92 ; Correctly handle zext returns.
93 declare zeroext i1 @foo_i1()
95 ; CHECK-LABEL: zext_i1
97 define zeroext i1 @zext_i1(i1 %k) {
99 br i1 %k, label %land.end, label %land.rhs
101 land.rhs: ; preds = %entry
102 %call1 = tail call zeroext i1 @foo_i1()
105 land.end: ; preds = %entry, %land.rhs
106 %0 = phi i1 [ false, %entry ], [ %call1, %land.rhs ]
110 ; We need to look through bitcasts when looking for tail calls in phi incoming
112 declare i32* @g_ret32()
113 define i8* @f_ret8(i8* %obj) nounwind {
114 ; OPT-LABEL: @f_ret8(
116 ; OPT-NEXT: [[CMP:%.*]] = icmp eq i8* [[OBJ:%.*]], null
117 ; OPT-NEXT: br i1 [[CMP]], label [[RETURN:%.*]], label [[IF_THEN:%.*]]
119 ; OPT-NEXT: [[PTR:%.*]] = tail call i32* @g_ret32()
120 ; OPT-NEXT: [[CASTED:%.*]] = bitcast i32* [[PTR]] to i8*
121 ; OPT-NEXT: ret i8* [[CASTED]]
123 ; OPT-NEXT: ret i8* [[OBJ]]
125 ; CHECK-LABEL: f_ret8:
126 ; CHECK: ## %bb.0: ## %entry
127 ; CHECK-NEXT: testq %rdi, %rdi
128 ; CHECK-NEXT: je LBB3_1
129 ; CHECK-NEXT: ## %bb.2: ## %if.then
130 ; CHECK-NEXT: jmp _g_ret32 ## TAILCALL
131 ; CHECK-NEXT: LBB3_1: ## %return
132 ; CHECK-NEXT: movq %rdi, %rax
135 %cmp = icmp eq i8* %obj, null
136 br i1 %cmp, label %return, label %if.then
139 %ptr = tail call i32* @g_ret32()
140 %casted = bitcast i32* %ptr to i8*
144 %retval = phi i8* [ %casted, %if.then ], [ %obj, %entry ]