llvm.org GIT mirror llvm / a116bba
Teach ObjCARC optimizer about equivalent PHIs when eliminating autoreleaseRV/retainRV pairs OptimizeAutoreleaseRVCall skips optimizing llvm.objc.autoreleaseReturnValue if it sees a user which is llvm.objc.retainAutoreleasedReturnValue, and if they have equivalent arguments (either identical or equivalent PHIs). It then assumes that ObjCARCOpt::OptimizeRetainRVCall will optimize the pair instead. Trouble is, ObjCARCOpt::OptimizeRetainRVCall doesn't know about equivalent PHIs so optimizes in a different way and we are left with an unoptimized llvm.objc.autoreleaseReturnValue. This teaches ObjCARCOpt::OptimizeRetainRVCall to also understand PHI equivalence. rdar://problem/47005143 Reviewed By: ahatanak Differential Revision: https://reviews.llvm.org/D56235 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@350284 91177308-0d34-0410-b5e6-96231b3b80d8 Pete Cooper 8 months ago
2 changed file(s) with 30 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
599599 }
600600 }
601601
602 // Track PHIs which are equivalent to our Arg.
603 SmallDenseSet EquivalentArgs;
604 EquivalentArgs.insert(Arg);
605
606 // Add PHIs that are equivalent to Arg to ArgUsers.
607 if (const PHINode *PN = dyn_cast(Arg)) {
608 SmallVector ArgUsers;
609 getEquivalentPHIs(*PN, ArgUsers);
610 EquivalentArgs.insert(ArgUsers.begin(), ArgUsers.end());
611 }
612
602613 // Check for being preceded by an objc_autoreleaseReturnValue on the same
603614 // pointer. In this case, we can delete the pair.
604615 BasicBlock::iterator I = RetainRV->getIterator(),
608619 --I;
609620 while (I != Begin && IsNoopInstruction(&*I));
610621 if (GetBasicARCInstKind(&*I) == ARCInstKind::AutoreleaseRV &&
611 GetArgRCIdentityRoot(&*I) == Arg) {
622 EquivalentArgs.count(GetArgRCIdentityRoot(&*I))) {
612623 Changed = true;
613624 ++NumPeeps;
614625
235235 define i8* @test19(i8* %p) {
236236 call i8* @llvm.objc.autoreleaseReturnValue(i8* %p)
237237 call i8* @llvm.objc.retainAutoreleasedReturnValue(i8* %p)
238 ret i8* %p
239 }
240
241 ; Delete autoreleaseRV+retainRV pairs when they have equivalent PHIs as inputs
242
243 ; CHECK: define i8* @test19phi(i8* %p) {
244 ; CHECK-NEXT: entry:
245 ; CHECK-NEXT: br label %test19bb
246 ; CHECK: test19bb:
247 ; CHECK-NEXT: ret i8* %p
248 define i8* @test19phi(i8* %p) {
249 entry:
250 br label %test19bb
251 test19bb:
252 %phi1 = phi i8* [ %p, %entry ]
253 %phi2 = phi i8* [ %p, %entry ]
254 call i8* @llvm.objc.autoreleaseReturnValue(i8* %phi1)
255 call i8* @llvm.objc.retainAutoreleasedReturnValue(i8* %phi2)
238256 ret i8* %p
239257 }
240258