1; RUN: llc < %s -mtriple=x86_64-apple-darwin | FileCheck %s 2 3; Teach CGP to dup returns to enable tail call optimization. 4; rdar://9147433 5 6define i32 @foo(i32 %x) nounwind ssp { 7; CHECK-LABEL: foo: 8entry: 9 switch i32 %x, label %return [ 10 i32 1, label %sw.bb 11 i32 2, label %sw.bb1 12 i32 3, label %sw.bb3 13 i32 4, label %sw.bb5 14 i32 5, label %sw.bb7 15 i32 6, label %sw.bb9 16 ] 17 18sw.bb: ; preds = %entry 19; CHECK: jmp _f1 20 %call = tail call i32 @f1() nounwind 21 br label %return 22 23sw.bb1: ; preds = %entry 24; CHECK: jmp _f2 25 %call2 = tail call i32 @f2() nounwind 26 br label %return 27 28sw.bb3: ; preds = %entry 29; CHECK: jmp _f3 30 %call4 = tail call i32 @f3() nounwind 31 br label %return 32 33sw.bb5: ; preds = %entry 34; CHECK: jmp _f4 35 %call6 = tail call i32 @f4() nounwind 36 br label %return 37 38sw.bb7: ; preds = %entry 39; CHECK: jmp _f5 40 %call8 = tail call i32 @f5() nounwind 41 br label %return 42 43sw.bb9: ; preds = %entry 44; CHECK: jmp _f6 45 %call10 = tail call i32 @f6() nounwind 46 br label %return 47 48return: ; preds = %entry, %sw.bb9, %sw.bb7, %sw.bb5, %sw.bb3, %sw.bb1, %sw.bb 49 %retval.0 = phi i32 [ %call10, %sw.bb9 ], [ %call8, %sw.bb7 ], [ %call6, %sw.bb5 ], [ %call4, %sw.bb3 ], [ %call2, %sw.bb1 ], [ %call, %sw.bb ], [ 0, %entry ] 50 ret i32 %retval.0 51} 52 53declare i32 @f1() 54 55declare i32 @f2() 56 57declare i32 @f3() 58 59declare i32 @f4() 60 61declare i32 @f5() 62 63declare i32 @f6() 64 65; rdar://11958338 66%0 = type opaque 67 68declare i8* @bar(i8*) uwtable optsize noinline ssp 69 70define hidden %0* @thingWithValue(i8* %self) uwtable ssp { 71entry: 72; CHECK-LABEL: thingWithValue: 73; CHECK: jmp _bar 74 br i1 undef, label %if.then.i, label %if.else.i 75 76if.then.i: ; preds = %entry 77 br label %someThingWithValue.exit 78 79if.else.i: ; preds = %entry 80 %call4.i = tail call i8* @bar(i8* undef) optsize 81 br label %someThingWithValue.exit 82 83someThingWithValue.exit: ; preds = %if.else.i, %if.then.i 84 %retval.0.in.i = phi i8* [ undef, %if.then.i ], [ %call4.i, %if.else.i ] 85 %retval.0.i = bitcast i8* %retval.0.in.i to %0* 86 ret %0* %retval.0.i 87} 88