[llvm-commits] [llvm] r154647 - in /llvm/trunk: lib/Transforms/Scalar/ObjCARC.cpp test/Transforms/ObjCARC/contract.ll
Dan Gohman
gohman at apple.com
Thu Apr 12 18:08:28 PDT 2012
Author: djg
Date: Thu Apr 12 20:08:28 2012
New Revision: 154647
URL: http://llvm.org/viewvc/llvm-project?rev=154647&view=rev
Log:
Use the new Use-aware dominates method to apply the objc runtime
library return value optimization for phi uses. Even when the
phi itself is not dominated, the specific use may be dominated.
Modified:
llvm/trunk/lib/Transforms/Scalar/ObjCARC.cpp
llvm/trunk/test/Transforms/ObjCARC/contract.ll
Modified: llvm/trunk/lib/Transforms/Scalar/ObjCARC.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/ObjCARC.cpp?rev=154647&r1=154646&r2=154647&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/ObjCARC.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/ObjCARC.cpp Thu Apr 12 20:08:28 2012
@@ -4109,16 +4109,12 @@
Use &U = UI.getUse();
unsigned OperandNo = UI.getOperandNo();
++UI; // Increment UI now, because we may unlink its element.
- Instruction *UserInst = dyn_cast<Instruction>(U.getUser());
- if (!UserInst)
- continue;
- // FIXME: dominates should return true for unreachable UserInst.
- if (DT->isReachableFromEntry(UserInst->getParent()) &&
- DT->dominates(Inst, UserInst)) {
+ if (DT->isReachableFromEntry(U) &&
+ DT->dominates(Inst, U)) {
Changed = true;
Instruction *Replacement = Inst;
Type *UseTy = U.get()->getType();
- if (PHINode *PHI = dyn_cast<PHINode>(UserInst)) {
+ if (PHINode *PHI = dyn_cast<PHINode>(U.getUser())) {
// For PHI nodes, insert the bitcast in the predecessor block.
unsigned ValNo =
PHINode::getIncomingValueNumForOperand(OperandNo);
@@ -4139,7 +4135,8 @@
}
} else {
if (Replacement->getType() != UseTy)
- Replacement = new BitCastInst(Replacement, UseTy, "", UserInst);
+ Replacement = new BitCastInst(Replacement, UseTy, "",
+ cast<Instruction>(U.getUser()));
U.set(Replacement);
}
}
Modified: llvm/trunk/test/Transforms/ObjCARC/contract.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/ObjCARC/contract.ll?rev=154647&r1=154646&r2=154647&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/ObjCARC/contract.ll (original)
+++ llvm/trunk/test/Transforms/ObjCARC/contract.ll Thu Apr 12 20:08:28 2012
@@ -143,3 +143,21 @@
%2 = tail call i8* @objc_autoreleaseReturnValue(i8* %p)
ret i8* %p
}
+
+; Do the return value substitution for PHI nodes too.
+
+; CHECK: define i8* @test8(
+; CHECK: %retval = phi i8* [ %p, %if.then ], [ null, %entry ]
+; CHECK: }
+define i8* @test8(i1 %x, i8* %c) {
+entry:
+ br i1 %x, label %return, label %if.then
+
+if.then: ; preds = %entry
+ %p = call i8* @objc_retain(i8* %c) nounwind
+ br label %return
+
+return: ; preds = %if.then, %entry
+ %retval = phi i8* [ %c, %if.then ], [ null, %entry ]
+ ret i8* %retval
+}
More information about the llvm-commits
mailing list