This is an archive of the discontinued LLVM Phabricator instance.

[ObjCARC] Traverse chain downwards to replace uses of argument passed to ObjC library call with call return
ClosedPublic

Authored by ahatanak on Sep 13 2016, 2:55 PM.

Details

Summary

ObjCARCContract::runOnFunction tries to replace uses of an argument passed to an objective-c library call with the call
return value. For example, in the following IR, it replaces uses of argument %9 and uses of the values discovered traversing the chain upwards (%7 and %8) with the call return %10, if they are dominated by the call to @objc_autoreleaseReturnValue. This transformation enables code-gen to tail-call the call to @objc_autoreleaseReturnValue, which is necessary to enable auto release return value optimization.

%7 = tail call i8* @objc_loadWeakRetained(i8** %6)
%8 = bitcast i8* %7 to %0*
%9 = bitcast %0* %8 to i8*
%10 = tail call i8* @objc_autoreleaseReturnValue(i8* %9)
ret %0* %8

Since r276727, llvm started removing redundant bitcasts and as a result started feeding the following IR to ARC contraction:

%7 = tail call i8* @objc_loadWeakRetained(i8** %6)
%8 = bitcast i8* %7 to %0*
%9 = tail call i8* @objc_autoreleaseReturnValue(i8* %7)
ret %0* %8

ARC contraction no longer does the optimization described above since it only traverses the chain upwards and fails to recognize that the function return can be replaced by the call return from @objc_autoreleaseReturnValue. This patch changes ObjCARCContract::runOnFunction to traverse the chain downwards too and replace uses of bitcasts with the call return.

rdar://problem/28011339

Diff Detail

Repository
rL LLVM

Event Timeline

ahatanak updated this revision to Diff 71239.Sep 13 2016, 2:55 PM
ahatanak retitled this revision from to [ObjCARC] Traverse chain downwards to replace uses of argument passed to ObjC library call with call return.
ahatanak updated this object.
ahatanak added reviewers: gottesmm, pete, rjmccall.
ahatanak added a subscriber: llvm-commits.
This revision was automatically updated to reflect the committed changes.