1*9880d681SAndroid Build Coastguard Worker; RUN: opt -objc-arc-contract -S < %s | FileCheck %s 2*9880d681SAndroid Build Coastguard Worker; rdar://9511608 3*9880d681SAndroid Build Coastguard Worker 4*9880d681SAndroid Build Coastguard Worker%0 = type opaque 5*9880d681SAndroid Build Coastguard Worker%1 = type opaque 6*9880d681SAndroid Build Coastguard Worker%2 = type { i64, i64 } 7*9880d681SAndroid Build Coastguard Worker%4 = type opaque 8*9880d681SAndroid Build Coastguard Worker 9*9880d681SAndroid Build Coastguard Workerdeclare %0* @"\01-[NSAttributedString(Terminal) pathAtIndex:effectiveRange:]"(%1*, i8* nocapture, i64, %2*) optsize 10*9880d681SAndroid Build Coastguard Workerdeclare i8* @objc_retainAutoreleasedReturnValue(i8*) 11*9880d681SAndroid Build Coastguard Workerdeclare i8* @objc_msgSend_fixup(i8*, i8*, ...) 12*9880d681SAndroid Build Coastguard Workerdeclare i8* @objc_msgSend(i8*, i8*, ...) 13*9880d681SAndroid Build Coastguard Workerdeclare void @objc_release(i8*) 14*9880d681SAndroid Build Coastguard Workerdeclare %2 @NSUnionRange(i64, i64, i64, i64) optsize 15*9880d681SAndroid Build Coastguard Workerdeclare i8* @objc_autoreleaseReturnValue(i8*) 16*9880d681SAndroid Build Coastguard Workerdeclare i8* @objc_autorelease(i8*) 17*9880d681SAndroid Build Coastguard Workerdeclare i32 @__gxx_personality_sj0(...) 18*9880d681SAndroid Build Coastguard Worker 19*9880d681SAndroid Build Coastguard Worker; Don't get in trouble on bugpointed code. 20*9880d681SAndroid Build Coastguard Worker 21*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: define void @test0( 22*9880d681SAndroid Build Coastguard Workerdefine void @test0() { 23*9880d681SAndroid Build Coastguard Workerbb: 24*9880d681SAndroid Build Coastguard Worker %tmp = bitcast %4* undef to i8* 25*9880d681SAndroid Build Coastguard Worker %tmp1 = tail call i8* @objc_retainAutoreleasedReturnValue(i8* %tmp) nounwind 26*9880d681SAndroid Build Coastguard Worker br label %bb3 27*9880d681SAndroid Build Coastguard Worker 28*9880d681SAndroid Build Coastguard Workerbb3: ; preds = %bb2 29*9880d681SAndroid Build Coastguard Worker br i1 undef, label %bb6, label %bb4 30*9880d681SAndroid Build Coastguard Worker 31*9880d681SAndroid Build Coastguard Workerbb4: ; preds = %bb3 32*9880d681SAndroid Build Coastguard Worker switch i64 undef, label %bb5 [ 33*9880d681SAndroid Build Coastguard Worker i64 9223372036854775807, label %bb6 34*9880d681SAndroid Build Coastguard Worker i64 0, label %bb6 35*9880d681SAndroid Build Coastguard Worker ] 36*9880d681SAndroid Build Coastguard Worker 37*9880d681SAndroid Build Coastguard Workerbb5: ; preds = %bb4 38*9880d681SAndroid Build Coastguard Worker br label %bb6 39*9880d681SAndroid Build Coastguard Worker 40*9880d681SAndroid Build Coastguard Workerbb6: ; preds = %bb5, %bb4, %bb4, %bb3 41*9880d681SAndroid Build Coastguard Worker %tmp7 = phi %4* [ undef, %bb5 ], [ undef, %bb4 ], [ undef, %bb3 ], [ undef, %bb4 ] 42*9880d681SAndroid Build Coastguard Worker unreachable 43*9880d681SAndroid Build Coastguard Worker} 44*9880d681SAndroid Build Coastguard Worker 45*9880d681SAndroid Build Coastguard Worker; When rewriting operands for a phi which has multiple operands 46*9880d681SAndroid Build Coastguard Worker; for the same block, use the exactly same value in each block. 47*9880d681SAndroid Build Coastguard Worker 48*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: define void @test1( 49*9880d681SAndroid Build Coastguard Worker; CHECK: %0 = bitcast i8* %tmp3 to %0* 50*9880d681SAndroid Build Coastguard Worker; CHECK: br i1 undef, label %bb7, label %bb7 51*9880d681SAndroid Build Coastguard Worker; CHECK: bb7: 52*9880d681SAndroid Build Coastguard Worker; CHECK: %tmp8 = phi %0* [ %0, %bb ], [ %0, %bb ] 53*9880d681SAndroid Build Coastguard Worker; CHECK: } 54*9880d681SAndroid Build Coastguard Workerdefine void @test1() { 55*9880d681SAndroid Build Coastguard Workerbb: 56*9880d681SAndroid Build Coastguard Worker %tmp = tail call %0* bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to %0* ()*)() 57*9880d681SAndroid Build Coastguard Worker %tmp2 = bitcast %0* %tmp to i8* 58*9880d681SAndroid Build Coastguard Worker %tmp3 = tail call i8* @objc_retainAutoreleasedReturnValue(i8* %tmp2) nounwind 59*9880d681SAndroid Build Coastguard Worker br i1 undef, label %bb7, label %bb7 60*9880d681SAndroid Build Coastguard Worker 61*9880d681SAndroid Build Coastguard Workerbb7: ; preds = %bb6, %bb6, %bb5 62*9880d681SAndroid Build Coastguard Worker %tmp8 = phi %0* [ %tmp, %bb ], [ %tmp, %bb ] 63*9880d681SAndroid Build Coastguard Worker unreachable 64*9880d681SAndroid Build Coastguard Worker} 65*9880d681SAndroid Build Coastguard Worker 66*9880d681SAndroid Build Coastguard Worker; When looking for the defining instruction for an objc_retainAutoreleasedReturnValue 67*9880d681SAndroid Build Coastguard Worker; call, handle the case where it's an invoke in a different basic block. 68*9880d681SAndroid Build Coastguard Worker; rdar://11714057 69*9880d681SAndroid Build Coastguard Worker 70*9880d681SAndroid Build Coastguard Worker; CHECK: define void @_Z6doTestP8NSString() personality i8* bitcast (i32 (...)* @__gxx_personality_sj0 to i8*) { 71*9880d681SAndroid Build Coastguard Worker; CHECK: invoke.cont: ; preds = %entry 72*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: call void asm sideeffect "mov\09r7, r7\09\09@ marker for objc_retainAutoreleaseReturnValue", ""() 73*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %tmp = tail call i8* @objc_retainAutoreleasedReturnValue(i8* %call) [[NUW:#[0-9]+]] 74*9880d681SAndroid Build Coastguard Worker; CHECK: } 75*9880d681SAndroid Build Coastguard Workerdefine void @_Z6doTestP8NSString() personality i8* bitcast (i32 (...)* @__gxx_personality_sj0 to i8*) { 76*9880d681SAndroid Build Coastguard Workerentry: 77*9880d681SAndroid Build Coastguard Worker %call = invoke i8* bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to i8* ()*)() 78*9880d681SAndroid Build Coastguard Worker to label %invoke.cont unwind label %lpad 79*9880d681SAndroid Build Coastguard Worker 80*9880d681SAndroid Build Coastguard Workerinvoke.cont: ; preds = %entry 81*9880d681SAndroid Build Coastguard Worker %tmp = tail call i8* @objc_retainAutoreleasedReturnValue(i8* %call) nounwind 82*9880d681SAndroid Build Coastguard Worker unreachable 83*9880d681SAndroid Build Coastguard Worker 84*9880d681SAndroid Build Coastguard Workerlpad: ; preds = %entry 85*9880d681SAndroid Build Coastguard Worker %tmp1 = landingpad { i8*, i32 } 86*9880d681SAndroid Build Coastguard Worker cleanup 87*9880d681SAndroid Build Coastguard Worker resume { i8*, i32 } undef 88*9880d681SAndroid Build Coastguard Worker} 89*9880d681SAndroid Build Coastguard Worker 90*9880d681SAndroid Build Coastguard Worker!clang.arc.retainAutoreleasedReturnValueMarker = !{!0} 91*9880d681SAndroid Build Coastguard Worker 92*9880d681SAndroid Build Coastguard Worker!0 = !{!"mov\09r7, r7\09\09@ marker for objc_retainAutoreleaseReturnValue"} 93*9880d681SAndroid Build Coastguard Worker 94*9880d681SAndroid Build Coastguard Worker; CHECK: attributes #0 = { optsize } 95*9880d681SAndroid Build Coastguard Worker; CHECK: attributes [[NUW]] = { nounwind } 96