[PATCH] D56235: Teach ObjCARC optimizer about equivalent PHIs when eliminating autoreleaseRV/retainRV pairs
Pete Cooper via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 2 17:42:59 PST 2019
This revision was automatically updated to reflect the committed changes.
pete marked an inline comment as done.
Closed by commit rL350284: Teach ObjCARC optimizer about equivalent PHIs when eliminating… (authored by pete, committed by ).
Changed prior to commit:
https://reviews.llvm.org/D56235?vs=179971&id=179987#toc
Repository:
rL LLVM
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D56235/new/
https://reviews.llvm.org/D56235
Files:
llvm/trunk/lib/Transforms/ObjCARC/ObjCARCOpts.cpp
llvm/trunk/test/Transforms/ObjCARC/rv.ll
Index: llvm/trunk/test/Transforms/ObjCARC/rv.ll
===================================================================
--- llvm/trunk/test/Transforms/ObjCARC/rv.ll
+++ llvm/trunk/test/Transforms/ObjCARC/rv.ll
@@ -239,6 +239,24 @@
ret i8* %p
}
+; Delete autoreleaseRV+retainRV pairs when they have equivalent PHIs as inputs
+
+; CHECK: define i8* @test19phi(i8* %p) {
+; CHECK-NEXT: entry:
+; CHECK-NEXT: br label %test19bb
+; CHECK: test19bb:
+; CHECK-NEXT: ret i8* %p
+define i8* @test19phi(i8* %p) {
+entry:
+ br label %test19bb
+test19bb:
+ %phi1 = phi i8* [ %p, %entry ]
+ %phi2 = phi i8* [ %p, %entry ]
+ call i8* @llvm.objc.autoreleaseReturnValue(i8* %phi1)
+ call i8* @llvm.objc.retainAutoreleasedReturnValue(i8* %phi2)
+ ret i8* %p
+}
+
; Like test19 but with plain autorelease.
; CHECK: define i8* @test20(i8* %p) {
Index: llvm/trunk/lib/Transforms/ObjCARC/ObjCARCOpts.cpp
===================================================================
--- llvm/trunk/lib/Transforms/ObjCARC/ObjCARCOpts.cpp
+++ llvm/trunk/lib/Transforms/ObjCARC/ObjCARCOpts.cpp
@@ -600,6 +600,17 @@
}
}
+ // Track PHIs which are equivalent to our Arg.
+ SmallDenseSet<const Value*, 2> EquivalentArgs;
+ EquivalentArgs.insert(Arg);
+
+ // Add PHIs that are equivalent to Arg to ArgUsers.
+ if (const PHINode *PN = dyn_cast<PHINode>(Arg)) {
+ SmallVector<const Value *, 2> ArgUsers;
+ getEquivalentPHIs(*PN, ArgUsers);
+ EquivalentArgs.insert(ArgUsers.begin(), ArgUsers.end());
+ }
+
// Check for being preceded by an objc_autoreleaseReturnValue on the same
// pointer. In this case, we can delete the pair.
BasicBlock::iterator I = RetainRV->getIterator(),
@@ -609,7 +620,7 @@
--I;
while (I != Begin && IsNoopInstruction(&*I));
if (GetBasicARCInstKind(&*I) == ARCInstKind::AutoreleaseRV &&
- GetArgRCIdentityRoot(&*I) == Arg) {
+ EquivalentArgs.count(GetArgRCIdentityRoot(&*I))) {
Changed = true;
++NumPeeps;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D56235.179987.patch
Type: text/x-patch
Size: 1982 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190103/782385c6/attachment.bin>
More information about the llvm-commits
mailing list