OSDN Git Service

[ObjCARC] Do not turn a call to @objc_autoreleaseReturnValue into a call
authorAkira Hatanaka <ahatanaka@apple.com>
Fri, 19 Jan 2018 23:51:13 +0000 (23:51 +0000)
committerAkira Hatanaka <ahatanaka@apple.com>
Fri, 19 Jan 2018 23:51:13 +0000 (23:51 +0000)
commit9b103df21bbf85b73d6094933646da2475c684b8
treed1d2411ba908f3046a4d87d9a20ebc9d527af579
parent4c73606e33bba4c18a77c28e5a853adfea421951
[ObjCARC] Do not turn a call to @objc_autoreleaseReturnValue into a call
to @objc_autorelease if its operand is a PHI and the PHI has an
equivalent value that is used by a return instruction.

For example, ARC optimizer shouldn't replace the call in the following
example, as doing so breaks the AutoreleaseRV/RetainRV optimization:

  %v1 = bitcast i32* %v0 to i8*
  br label %bb3
bb2:
  %v3 = bitcast i32* %v2 to i8*
  br label %bb3
bb3:
  %p = phi i8* [ %v1, %bb1 ], [ %v3, %bb2 ]
  %retval = phi i32* [ %v0, %bb1 ], [ %v2, %bb2 ] ; equivalent to %p
  %v4 = tail call i8* @objc_autoreleaseReturnValue(i8* %p)
  ret i32* %retval

Also, make sure ObjCARCContract replaces @objc_autoreleaseReturnValue's
operand uses with its value so that the call gets tail-called.

rdar://problem/15894705

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@323009 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Transforms/ObjCARC/ObjCARC.h
lib/Transforms/ObjCARC/ObjCARCContract.cpp
lib/Transforms/ObjCARC/ObjCARCOpts.cpp
test/Transforms/ObjCARC/contract-replace-arg-use.ll
test/Transforms/ObjCARC/rv.ll