Skip to content

Commit 238597d

Browse files
committed
Fix new test
1 parent 1431fe3 commit 238597d

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

llvm/lib/Transforms/ObjCARC/ObjCARCContract.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -660,13 +660,15 @@ bool ObjCARCContract::run(Function &F, AAResults *A, DominatorTree *D) {
660660
};
661661

662662
Value *Arg = cast<CallInst>(Inst)->getArgOperand(0);
663-
664663
ReplaceArgUses(Arg);
665664

666-
Arg = Arg->stripPointerCastsAndAliases();
665+
Value *Stripped = Arg->stripPointerCastsAndAliases();
666+
if (Stripped != Arg)
667+
ReplaceArgUses(Stripped);
668+
667669
// If Arg is a PHI node, get PHIs that are equivalent to it and replace
668670
// their uses.
669-
if (PHINode *PN = dyn_cast<PHINode>(Arg)) {
671+
if (PHINode *PN = dyn_cast<PHINode>(Stripped)) {
670672
SmallVector<Value *, 1> PHIList;
671673
getEquivalentPHIs(*PN, PHIList);
672674
for (Value *PHI : PHIList)

llvm/test/Transforms/ObjCARC/contract.ll

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,22 @@ define void @test14(ptr %a, ptr %b) {
234234
ret void
235235
}
236236

237+
define void @test15(ptr %x) {
238+
; CHECK-LABEL: define void @test15(
239+
; CHECK-SAME: ptr [[X:%.*]]) {
240+
; CHECK-NEXT: [[Y:%.*]] = getelementptr inbounds ptr, ptr [[X]], i32 0
241+
; CHECK-NEXT: [[V0:%.*]] = call ptr @llvm.objc.retain(ptr [[Y]]) #[[ATTR0:[0-9]+]]
242+
; CHECK-NEXT: call void @use_pointer(ptr [[V0]])
243+
; CHECK-NEXT: call void @use_pointer(ptr [[V0]])
244+
; CHECK-NEXT: ret void
245+
;
246+
%y = getelementptr inbounds ptr, ptr %x, i32 0
247+
%v0 = call ptr @llvm.objc.retain(ptr %y) nounwind
248+
call void @use_pointer(ptr %x)
249+
call void @use_pointer(ptr %y)
250+
ret void
251+
}
252+
237253
declare void @llvm.objc.clang.arc.use(...) nounwind
238254
declare void @llvm.objc.clang.arc.noop.use(...) nounwind
239255

0 commit comments

Comments
 (0)