OSDN Git Service

[ObjCARC] Traverse chain downwards to replace uses of argument passed to
authorAkira Hatanaka <ahatanaka@apple.com>
Tue, 13 Sep 2016 23:43:11 +0000 (23:43 +0000)
committerAkira Hatanaka <ahatanaka@apple.com>
Tue, 13 Sep 2016 23:43:11 +0000 (23:43 +0000)
commit90a2aecbedd11b9ef5ddec7bbe941a7dfd53d898
tree015b9a424987c4fef251f210d669fe20ecf7b496
parente7f7e181274d0e53c94942ec9bf488080894ac53
[ObjCARC] Traverse chain downwards to replace uses of argument passed to
ObjC library call with call return.

ARC contraction 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. This commit changes
ARC contraction to traverse the chain downwards too and replace uses of
bitcasts with the call return.

rdar://problem/28011339

Differential Revision: https://reviews.llvm.org/D24523

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@281419 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Transforms/ObjCARC/ObjCARCContract.cpp
test/Transforms/ObjCARC/contract-replace-arg-use.ll [new file with mode: 0644]