This is needed to enable performing tail-call optimization on calls to objc_autorelease in MRR, which enables objc_autorelease to perform the retainRV/ autoreleaseRV handshake that keeps the returned object out of the autorelease pool.
With this patch, the backend can tail-call the call to objc_autorelease in function bar in the code below.
// We currently tail call the call to `objc_autorelease` in `foo` NSObject *foo(void) { NSObject *t = [NSObject new]; return [t autorelease]; } // We currently don't tail-call the call to `objc_autorelease` in `bar` because its result isn't used by the return instruction. // // %call = tail call i8* bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to i8* (i8*, i8*)*)(i8* %0, i8* %1) // %2 = bitcast i8* %call to %0* // %3 = tail call i8* @objc_autorelease(i8* %call) #2 // ret %0* %2 NSObject *bar(void) { NSObject *t = [NSObject new]; [t autorelease]; return t; }
rdar://problem/50353574