diff options
-rw-r--r-- | llvm/lib/Transforms/ObjCARC/ObjCARCOpts.cpp | 11 | ||||
-rw-r--r-- | llvm/test/Transforms/ObjCARC/basic.ll | 20 |
2 files changed, 28 insertions, 3 deletions
diff --git a/llvm/lib/Transforms/ObjCARC/ObjCARCOpts.cpp b/llvm/lib/Transforms/ObjCARC/ObjCARCOpts.cpp index 8c0a90843ef..6692d950da2 100644 --- a/llvm/lib/Transforms/ObjCARC/ObjCARCOpts.cpp +++ b/llvm/lib/Transforms/ObjCARC/ObjCARCOpts.cpp @@ -808,9 +808,14 @@ void ObjCARCOpt::OptimizeIndividualCalls(Function &F) { // If Arg is a PHI, and one or more incoming values to the // PHI are null, and the call is control-equivalent to the PHI, and there - // are no relevant side effects between the PHI and the call, the call - // could be pushed up to just those paths with non-null incoming values. - // For now, don't bother splitting critical edges for this. + // are no relevant side effects between the PHI and the call, and the call + // is not a release that doesn't have the clang.imprecise_release tag, the + // call could be pushed up to just those paths with non-null incoming + // values. For now, don't bother splitting critical edges for this. + if (Class == ARCInstKind::Release && + !Inst->getMetadata(MDKindCache.get(ARCMDKindID::ImpreciseRelease))) + continue; + SmallVector<std::pair<Instruction *, const Value *>, 4> Worklist; Worklist.push_back(std::make_pair(Inst, Arg)); do { diff --git a/llvm/test/Transforms/ObjCARC/basic.ll b/llvm/test/Transforms/ObjCARC/basic.ll index cecaa3f2b4d..70b83b93138 100644 --- a/llvm/test/Transforms/ObjCARC/basic.ll +++ b/llvm/test/Transforms/ObjCARC/basic.ll @@ -1345,6 +1345,26 @@ B: C: %h = phi double* [ null, %A ], [ %p, %B ] %c = bitcast double* %h to i8* + call void @objc_release(i8* %c), !clang.imprecise_release !0 + ret void +} + +; Do not move an objc_release that doesn't have the clang.imprecise_release tag. + +; CHECK-LABEL: define void @test22_precise( +; CHECK: %[[P0:.*]] = phi double* +; CHECK: %[[V0:.*]] = bitcast double* %[[P0]] to i8* +; CHECK: call void @objc_release(i8* %[[V0]]) +; CHECK: ret void +define void @test22_precise(double* %p, i1 %a) { + br i1 %a, label %A, label %B +A: + br label %C +B: + br label %C +C: + %h = phi double* [ null, %A ], [ %p, %B ] + %c = bitcast double* %h to i8* call void @objc_release(i8* %c) ret void } |