Skip to content

ObjCARC: Fix regression from using ConstantData uselists #139609

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

arsenm
Copy link
Contributor

@arsenm arsenm commented May 12, 2025

Fixes regression after 9383fb2

@arsenm arsenm marked this pull request as ready for review May 12, 2025 19:41
Copy link
Contributor Author

arsenm commented May 12, 2025

This stack of pull requests is managed by Graphite. Learn more about stacking.

@llvmbot
Copy link
Member

llvmbot commented May 12, 2025

@llvm/pr-subscribers-llvm-transforms

Author: Matt Arsenault (arsenm)

Changes

Fixes regression after 9383fb2


Full diff: https://github.com/llvm/llvm-project/pull/139609.diff

2 Files Affected:

  • (modified) llvm/lib/Transforms/ObjCARC/ProvenanceAnalysis.cpp (+3)
  • (added) llvm/test/Transforms/ObjCARC/pr138961-regression.ll (+42)
diff --git a/llvm/lib/Transforms/ObjCARC/ProvenanceAnalysis.cpp b/llvm/lib/Transforms/ObjCARC/ProvenanceAnalysis.cpp
index 155c9493e838f..e491e5dcbefbb 100644
--- a/llvm/lib/Transforms/ObjCARC/ProvenanceAnalysis.cpp
+++ b/llvm/lib/Transforms/ObjCARC/ProvenanceAnalysis.cpp
@@ -78,6 +78,9 @@ bool ProvenanceAnalysis::relatedPHI(const PHINode *A,
 /// Test if the value of P, or any value covered by its provenance, is ever
 /// stored within the function (not counting callees).
 static bool IsStoredObjCPointer(const Value *P) {
+  if (!P->hasUseList())
+    return true; // Assume the worst for a constant pointer.
+
   SmallPtrSet<const Value *, 8> Visited;
   SmallVector<const Value *, 8> Worklist;
   Worklist.push_back(P);
diff --git a/llvm/test/Transforms/ObjCARC/pr138961-regression.ll b/llvm/test/Transforms/ObjCARC/pr138961-regression.ll
new file mode 100644
index 0000000000000..c9a2275e22d74
--- /dev/null
+++ b/llvm/test/Transforms/ObjCARC/pr138961-regression.ll
@@ -0,0 +1,42 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
+; RUN: opt -S -passes=objc-arc < %s | FileCheck %s
+
+target triple = "x86_64-apple-macosx11.0.0"
+
+declare ptr @llvm.objc.retain(ptr returned) #0
+declare void @llvm.objc.release(ptr) #0
+
+declare ptr @foo(ptr)
+
+define i1 @_ZN8GrMtlGpu20readOrTransferPixelsEP9GrSurface7SkIRect11GrColorTypePU19objcproto9MTLBuffer11objc_objectmmm(ptr %this) #1 {
+; CHECK-LABEL: define i1 @_ZN8GrMtlGpu20readOrTransferPixelsEP9GrSurface7SkIRect11GrColorTypePU19objcproto9MTLBuffer11objc_objectmmm(
+; CHECK-SAME: ptr [[THIS:%.*]]) #[[ATTR1:[0-9]+]] {
+; CHECK-NEXT:  [[ENTRY:.*]]:
+; CHECK-NEXT:    [[RETAIN:%.*]] = tail call ptr @llvm.objc.retain(ptr [[THIS]]) #[[ATTR0:[0-9]+]]
+; CHECK-NEXT:    br i1 false, label %[[CLEANUP66:.*]], label %[[IF_END30:.*]]
+; CHECK:       [[IF_END30]]:
+; CHECK-NEXT:    [[LD_PTR:%.*]] = load ptr, ptr [[THIS]], align 8
+; CHECK-NEXT:    call void @foo(ptr [[LD_PTR]])
+; CHECK-NEXT:    br label %[[CLEANUP66]]
+; CHECK:       [[CLEANUP66]]:
+; CHECK-NEXT:    [[MTLTEXTURE_1103:%.*]] = phi ptr [ null, %[[ENTRY]] ], [ [[THIS]], %[[IF_END30]] ]
+; CHECK-NEXT:    tail call void @llvm.objc.release(ptr [[MTLTEXTURE_1103]]) #[[ATTR0]]
+; CHECK-NEXT:    ret i1 false
+;
+entry:
+  %retain = tail call ptr @llvm.objc.retain(ptr %this)
+  br i1 false, label %cleanup66, label %if.end30
+
+if.end30:                                         ; preds = %entry
+  %ld.ptr = load ptr, ptr %this, align 8
+  call void @foo(ptr %ld.ptr)
+  br label %cleanup66
+
+cleanup66:                                        ; preds = %if.end30, %entry
+  %mtlTexture.1103 = phi ptr [ null, %entry ], [ %this, %if.end30 ]
+  tail call void @llvm.objc.release(ptr %mtlTexture.1103)
+  ret i1 false
+}
+
+attributes #0 = { nounwind }
+attributes #1 = { null_pointer_is_valid }

@zmodem zmodem requested a review from nikic May 13, 2025 08:32
Copy link
Collaborator

@zmodem zmodem left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, ship it :)

@arsenm arsenm merged commit 6d35ec2 into main May 13, 2025
15 checks passed
@arsenm arsenm deleted the users/arsenm/objcarc/fix-constantdata-uselist-regression branch May 13, 2025 08:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants