diff options
author | Akira Hatanaka <ahatanaka@apple.com> | 2018-01-19 23:51:13 +0000 |
---|---|---|
committer | Akira Hatanaka <ahatanaka@apple.com> | 2018-01-19 23:51:13 +0000 |
commit | 73ceb50d8555fa7460957a0346bcb4002e5eff42 (patch) | |
tree | 09741d844241f44106fe0310c997407a3a8cc47f /llvm/lib/Transforms/ObjCARC/ObjCARCOpts.cpp | |
parent | 9d540f1539f65b18ef4b9295da65c51aba8466e0 (diff) | |
download | bcm5719-llvm-73ceb50d8555fa7460957a0346bcb4002e5eff42.tar.gz bcm5719-llvm-73ceb50d8555fa7460957a0346bcb4002e5eff42.zip |
[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
llvm-svn: 323009
Diffstat (limited to 'llvm/lib/Transforms/ObjCARC/ObjCARCOpts.cpp')
-rw-r--r-- | llvm/lib/Transforms/ObjCARC/ObjCARCOpts.cpp | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/ObjCARC/ObjCARCOpts.cpp b/llvm/lib/Transforms/ObjCARC/ObjCARCOpts.cpp index 99ed6863c22..ecec85444b1 100644 --- a/llvm/lib/Transforms/ObjCARC/ObjCARCOpts.cpp +++ b/llvm/lib/Transforms/ObjCARC/ObjCARCOpts.cpp @@ -652,6 +652,11 @@ void ObjCARCOpt::OptimizeAutoreleaseRVCall(Function &F, SmallVector<const Value *, 2> Users; Users.push_back(Ptr); + + // Add PHIs that are equivalent to Ptr to Users. + if (const PHINode *PN = dyn_cast<PHINode>(Ptr)) + getEquivalentPHIs(*PN, Users); + do { Ptr = Users.pop_back_val(); for (const User *U : Ptr->users()) { |