Skip to content

Revert "[ObjCARC][Contract] Optimize bundled RetainRV to ClaimRV" #139780

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
merged 1 commit into from
May 13, 2025

Conversation

citymarina
Copy link
Contributor

Reverts #139762 for breaking bots

@citymarina citymarina merged commit 5bb8e9d into main May 13, 2025
4 of 9 checks passed
@citymarina citymarina deleted the revert-139762-objc-claim-oops3 branch May 13, 2025 19:20
@llvmbot
Copy link
Member

llvmbot commented May 13, 2025

@llvm/pr-subscribers-llvm-transforms

Author: Marina Taylor (citymarina)

Changes

Reverts llvm/llvm-project#139762 for breaking bots


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

6 Files Affected:

  • (modified) llvm/lib/Transforms/ObjCARC/ARCRuntimeEntryPoints.h (-8)
  • (modified) llvm/lib/Transforms/ObjCARC/ObjCARC.cpp (-29)
  • (modified) llvm/lib/Transforms/ObjCARC/ObjCARC.h (+1-6)
  • (modified) llvm/lib/Transforms/ObjCARC/ObjCARCContract.cpp (+1-45)
  • (modified) llvm/lib/Transforms/ObjCARC/ObjCARCOpts.cpp (+1-1)
  • (removed) llvm/test/Transforms/ObjCARC/contract-attached-call-retain-to-claim.ll (-35)
diff --git a/llvm/lib/Transforms/ObjCARC/ARCRuntimeEntryPoints.h b/llvm/lib/Transforms/ObjCARC/ARCRuntimeEntryPoints.h
index 3fa844eda21cf..0dedd0207571b 100644
--- a/llvm/lib/Transforms/ObjCARC/ARCRuntimeEntryPoints.h
+++ b/llvm/lib/Transforms/ObjCARC/ARCRuntimeEntryPoints.h
@@ -42,7 +42,6 @@ enum class ARCRuntimeEntryPointKind {
   Autorelease,
   StoreStrong,
   RetainRV,
-  ClaimRV,
   UnsafeClaimRV,
   RetainAutorelease,
   RetainAutoreleaseRV,
@@ -63,7 +62,6 @@ class ARCRuntimeEntryPoints {
     Autorelease = nullptr;
     StoreStrong = nullptr;
     RetainRV = nullptr;
-    ClaimRV = nullptr;
     UnsafeClaimRV = nullptr;
     RetainAutorelease = nullptr;
     RetainAutoreleaseRV = nullptr;
@@ -89,9 +87,6 @@ class ARCRuntimeEntryPoints {
     case ARCRuntimeEntryPointKind::RetainRV:
       return getIntrinsicEntryPoint(RetainRV,
                                 Intrinsic::objc_retainAutoreleasedReturnValue);
-    case ARCRuntimeEntryPointKind::ClaimRV:
-      return getIntrinsicEntryPoint(
-          ClaimRV, Intrinsic::objc_claimAutoreleasedReturnValue);
     case ARCRuntimeEntryPointKind::UnsafeClaimRV:
       return getIntrinsicEntryPoint(
           UnsafeClaimRV, Intrinsic::objc_unsafeClaimAutoreleasedReturnValue);
@@ -131,9 +126,6 @@ class ARCRuntimeEntryPoints {
   /// Declaration for objc_retainAutoreleasedReturnValue().
   Function *RetainRV = nullptr;
 
-  /// Declaration for objc_claimAutoreleasedReturnValue().
-  Function *ClaimRV = nullptr;
-
   /// Declaration for objc_unsafeClaimAutoreleasedReturnValue().
   Function *UnsafeClaimRV = nullptr;
 
diff --git a/llvm/lib/Transforms/ObjCARC/ObjCARC.cpp b/llvm/lib/Transforms/ObjCARC/ObjCARC.cpp
index 32e7092e80117..b6ade1c29a2b5 100644
--- a/llvm/lib/Transforms/ObjCARC/ObjCARC.cpp
+++ b/llvm/lib/Transforms/ObjCARC/ObjCARC.cpp
@@ -101,37 +101,8 @@ BundledRetainClaimRVs::~BundledRetainClaimRVs() {
       // can't be tail calls.
       if (auto *CI = dyn_cast<CallInst>(CB))
         CI->setTailCallKind(CallInst::TCK_NoTail);
-
-      // We can also do one final optimization: modify the bundle in the
-      // annotated call, to change the bundle operand from
-      //   objc_retainAutoreleasedReturnValue
-      // to:
-      //   objc_claimAutoreleasedReturnValue
-      // allowing the marker to be omitted from the bundle expansion later.
-      //
-      // Note that, confusingly, ClaimRV is semantically equivalent to RetainRV,
-      // and only differs in that it doesn't require the marker.
-      // The bundle provides the guarantee that we're emitting the ClaimRV call
-      // adjacent to the original call, and providing that guarantee is the
-      // only difference between ClaimRV and RetainRV.
-      //
-      // UnsafeClaimRV has a different RC contract entirely.
-
-      // Find the clang.arc.attachedcall bundle, and rewrite its operand.
-      if (UseClaimRV) {
-        for (auto OBI : CB->bundle_op_infos()) {
-          auto OBU = CB->operandBundleFromBundleOpInfo(OBI);
-          if (OBU.getTagID() == LLVMContext::OB_clang_arc_attachedcall &&
-              OBU.Inputs[0] == EP.get(ARCRuntimeEntryPointKind::RetainRV)) {
-            CB->setOperand(OBI.Begin,
-                           EP.get(ARCRuntimeEntryPointKind::ClaimRV));
-            break;
-          }
-        }
-      }
     }
 
-    // Erase the RV call we emitted earlier: it's already in the bundle.
     EraseInstruction(P.first);
   }
 
diff --git a/llvm/lib/Transforms/ObjCARC/ObjCARC.h b/llvm/lib/Transforms/ObjCARC/ObjCARC.h
index d0bff00446aa0..f4d7c92d499c1 100644
--- a/llvm/lib/Transforms/ObjCARC/ObjCARC.h
+++ b/llvm/lib/Transforms/ObjCARC/ObjCARC.h
@@ -22,7 +22,6 @@
 #ifndef LLVM_LIB_TRANSFORMS_OBJCARC_OBJCARC_H
 #define LLVM_LIB_TRANSFORMS_OBJCARC_OBJCARC_H
 
-#include "ARCRuntimeEntryPoints.h"
 #include "llvm/Analysis/ObjCARCAnalysisUtils.h"
 #include "llvm/Analysis/ObjCARCUtil.h"
 #include "llvm/IR/EHPersonalities.h"
@@ -105,9 +104,7 @@ CallInst *createCallInstWithColors(
 
 class BundledRetainClaimRVs {
 public:
-  BundledRetainClaimRVs(ARCRuntimeEntryPoints &EP, bool ContractPass,
-                        bool UseClaimRV)
-      : EP(EP), ContractPass(ContractPass), UseClaimRV(UseClaimRV) {}
+  BundledRetainClaimRVs(bool ContractPass) : ContractPass(ContractPass) {}
   ~BundledRetainClaimRVs();
 
   /// Insert a retainRV/claimRV call to the normal destination blocks of invokes
@@ -158,9 +155,7 @@ class BundledRetainClaimRVs {
   /// A map of inserted retainRV/claimRV calls to annotated calls/invokes.
   DenseMap<CallInst *, CallBase *> RVCalls;
 
-  ARCRuntimeEntryPoints &EP;
   bool ContractPass;
-  bool UseClaimRV;
 };
 
 } // end namespace objcarc
diff --git a/llvm/lib/Transforms/ObjCARC/ObjCARCContract.cpp b/llvm/lib/Transforms/ObjCARC/ObjCARCContract.cpp
index 86d7e2f07c1d9..e11748b2c9dbb 100644
--- a/llvm/lib/Transforms/ObjCARC/ObjCARCContract.cpp
+++ b/llvm/lib/Transforms/ObjCARC/ObjCARCContract.cpp
@@ -42,7 +42,6 @@
 #include "llvm/InitializePasses.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/raw_ostream.h"
-#include "llvm/TargetParser/Triple.h"
 #include "llvm/Transforms/ObjCARC.h"
 
 using namespace llvm;
@@ -53,11 +52,6 @@ using namespace llvm::objcarc;
 STATISTIC(NumPeeps,       "Number of calls peephole-optimized");
 STATISTIC(NumStoreStrongs, "Number objc_storeStrong calls formed");
 
-static cl::opt<cl::boolOrDefault> UseObjCClaimRV(
-    "arc-contract-use-objc-claim-rv",
-    cl::desc(
-        "Enable generation of calls to objc_claimAutoreleasedReturnValue"));
-
 //===----------------------------------------------------------------------===//
 //                                Declarations
 //===----------------------------------------------------------------------===//
@@ -80,9 +74,6 @@ class ObjCARCContract {
   /// A flag indicating whether this optimization pass should run.
   bool Run;
 
-  /// Whether objc_claimAutoreleasedReturnValue is available.
-  bool HasClaimRV = false;
-
   /// The inline asm string to insert between calls and RetainRV calls to make
   /// the optimization work on targets which need it.
   const MDString *RVInstMarker;
@@ -526,39 +517,6 @@ bool ObjCARCContract::tryToPeepholeInstruction(
   }
 }
 
-/// Should we use objc_claimAutoreleasedReturnValue?
-static bool useClaimRuntimeCall(Module &M) {
-  // Let the flag override our OS-based default.
-  if (UseObjCClaimRV != cl::BOU_UNSET)
-    return UseObjCClaimRV == cl::BOU_TRUE;
-
-  Triple TT(M.getTargetTriple());
-
-  // On x86_64, claimARV doesn't make sense, as the marker isn't actually a nop
-  // there (it's needed by the calling convention).
-  if (!TT.isAArch64())
-    return false;
-
-  unsigned Major = TT.getOSMajorVersion();
-  switch (TT.getOS()) {
-  default:
-    return false;
-  case Triple::IOS:
-  case Triple::TvOS:
-    return Major >= 16;
-  case Triple::WatchOS:
-    return Major >= 9;
-  case Triple::BridgeOS:
-    return Major >= 7;
-  case Triple::MacOSX:
-    return Major >= 13;
-  case Triple::Darwin:
-    return Major >= 21;
-  }
-
-  return false;
-}
-
 //===----------------------------------------------------------------------===//
 //                              Top Level Driver
 //===----------------------------------------------------------------------===//
@@ -570,8 +528,6 @@ bool ObjCARCContract::init(Module &M) {
 
   EP.init(&M);
 
-  HasClaimRV = useClaimRuntimeCall(M);
-
   // Initialize RVInstMarker.
   RVInstMarker = getRVInstMarker(M);
 
@@ -589,7 +545,7 @@ bool ObjCARCContract::run(Function &F, AAResults *A, DominatorTree *D) {
   AA = A;
   DT = D;
   PA.setAA(A);
-  BundledRetainClaimRVs BRV(EP, /*ContractPass=*/true, HasClaimRV);
+  BundledRetainClaimRVs BRV(/*ContractPass=*/true);
   BundledInsts = &BRV;
 
   std::pair<bool, bool> R = BundledInsts->insertAfterInvokes(F, DT);
diff --git a/llvm/lib/Transforms/ObjCARC/ObjCARCOpts.cpp b/llvm/lib/Transforms/ObjCARC/ObjCARCOpts.cpp
index 5eb3f51d38945..2ef87f531dfae 100644
--- a/llvm/lib/Transforms/ObjCARC/ObjCARCOpts.cpp
+++ b/llvm/lib/Transforms/ObjCARC/ObjCARCOpts.cpp
@@ -2423,7 +2423,7 @@ bool ObjCARCOpt::run(Function &F, AAResults &AA) {
     return false;
 
   Changed = CFGChanged = false;
-  BundledRetainClaimRVs BRV(EP, /*ContractPass=*/false, /*UseClaimRV=*/false);
+  BundledRetainClaimRVs BRV(/*ContractPass=*/false);
   BundledInsts = &BRV;
 
   LLVM_DEBUG(dbgs() << "<<< ObjCARCOpt: Visiting Function: " << F.getName()
diff --git a/llvm/test/Transforms/ObjCARC/contract-attached-call-retain-to-claim.ll b/llvm/test/Transforms/ObjCARC/contract-attached-call-retain-to-claim.ll
deleted file mode 100644
index d0b8ce97d6517..0000000000000
--- a/llvm/test/Transforms/ObjCARC/contract-attached-call-retain-to-claim.ll
+++ /dev/null
@@ -1,35 +0,0 @@
-; RUN: opt -passes=objc-arc-contract -arc-contract-use-objc-claim-rv=1 -S < %s | FileCheck %s --check-prefixes=CHECK,CLAIM
-; RUN: opt -passes=objc-arc-contract -arc-contract-use-objc-claim-rv=0 -S < %s | FileCheck %s --check-prefixes=CHECK,RETAIN
-
-; CHECK-LABEL: define void @test0() {
-; CLAIM: %[[CALL:.*]] = notail call ptr @foo() [ "clang.arc.attachedcall"(ptr @llvm.objc.claimAutoreleasedReturnValue) ]
-; RETAIN: %[[CALL:.*]] = notail call ptr @foo() [ "clang.arc.attachedcall"(ptr @llvm.objc.retainAutoreleasedReturnValue) ]
-; CHECK-NEXT: ret void
-
-define void @test0() {
-  %call1 = call ptr @foo() [ "clang.arc.attachedcall"(ptr @llvm.objc.retainAutoreleasedReturnValue) ]
-  ret void
-}
-
-; CHECK-LABEL: define void @test1() {
-; CHECK: %[[CALL:.*]] = notail call ptr @foo() [ "clang.arc.attachedcall"(ptr @llvm.objc.unsafeClaimAutoreleasedReturnValue) ]
-; CHECK-NEXT: ret void
-
-define void @test1() {
-  %call1 = call ptr @foo() [ "clang.arc.attachedcall"(ptr @llvm.objc.unsafeClaimAutoreleasedReturnValue) ]
-  ret void
-}
-
-; CHECK-LABEL: define void @test2() {
-; CLAIM: %[[CALL:.*]] = notail call ptr @foo() [ "clang.arc.attachedcall"(ptr @llvm.objc.claimAutoreleasedReturnValue), "otherbundle"() ]
-; RETAIN: %[[CALL:.*]] = notail call ptr @foo() [ "clang.arc.attachedcall"(ptr @llvm.objc.retainAutoreleasedReturnValue), "otherbundle"() ]
-; CHECK-NEXT: ret void
-
-define void @test2() {
-  %call1 = call ptr @foo() [ "clang.arc.attachedcall"(ptr @llvm.objc.retainAutoreleasedReturnValue), "otherbundle"() ]
-  ret void
-}
-
-declare ptr @foo()
-declare ptr @llvm.objc.retainAutoreleasedReturnValue(ptr)
-declare ptr @llvm.objc.unsafeClaimAutoreleasedReturnValue(ptr)

@llvm-ci
Copy link
Collaborator

llvm-ci commented May 13, 2025

LLVM Buildbot has detected a new failure on builder lldb-arm-ubuntu running on linaro-lldb-arm-ubuntu while building llvm at step 6 "test".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/18/builds/15949

Here is the relevant piece of the build log for the reference
Step 6 (test) failure: build (failure)
...
PASS: lldb-shell :: Subprocess/clone-follow-child.test (1626 of 3041)
PASS: lldb-shell :: Subprocess/clone-follow-parent-softbp.test (1627 of 3041)
PASS: lldb-shell :: Subprocess/clone-follow-parent.test (1628 of 3041)
PASS: lldb-shell :: Subprocess/clone-follow-child-wp.test (1629 of 3041)
PASS: lldb-shell :: Subprocess/fork-follow-child-softbp.test (1630 of 3041)
PASS: lldb-shell :: Subprocess/fork-follow-child.test (1631 of 3041)
PASS: lldb-shell :: Subprocess/clone-follow-parent-wp.test (1632 of 3041)
PASS: lldb-shell :: Subprocess/fork-follow-parent-softbp.test (1633 of 3041)
PASS: lldb-shell :: Subprocess/fork-follow-parent.test (1634 of 3041)
UNRESOLVED: lldb-api :: tools/lldb-server/TestLldbGdbServer.py (1635 of 3041)
******************** TEST 'lldb-api :: tools/lldb-server/TestLldbGdbServer.py' FAILED ********************
Script:
--
/usr/bin/python3.10 /home/tcwg-buildbot/worker/lldb-arm-ubuntu/llvm-project/lldb/test/API/dotest.py -u CXXFLAGS -u CFLAGS --env LLVM_LIBS_DIR=/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/./lib --env LLVM_INCLUDE_DIR=/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/include --env LLVM_TOOLS_DIR=/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/./bin --arch armv8l --build-dir /home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/lldb-test-build.noindex --lldb-module-cache-dir /home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/lldb-test-build.noindex/module-cache-lldb/lldb-api --clang-module-cache-dir /home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/lldb-test-build.noindex/module-cache-clang/lldb-api --executable /home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/./bin/lldb --compiler /home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/./bin/clang --dsymutil /home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/./bin/dsymutil --make /usr/bin/gmake --llvm-tools-dir /home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/./bin --lldb-obj-root /home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/tools/lldb --lldb-libs-dir /home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/./lib /home/tcwg-buildbot/worker/lldb-arm-ubuntu/llvm-project/lldb/test/API/tools/lldb-server -p TestLldbGdbServer.py
--
Exit Code: 1

Command Output (stdout):
--
lldb version 21.0.0git (https://github.com/llvm/llvm-project.git revision 5bb8e9db5f59dc2d3d8658f5b03577f9296be267)
  clang revision 5bb8e9db5f59dc2d3d8658f5b03577f9296be267
  llvm revision 5bb8e9db5f59dc2d3d8658f5b03577f9296be267
Skipping the following test categories: ['libc++', 'dsym', 'gmodules', 'debugserver', 'objc']

--
Command Output (stderr):
--
UNSUPPORTED: LLDB (/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/bin/clang-arm) :: test_Hc_then_Csignal_signals_correct_thread_launch_debugserver (TestLldbGdbServer.LldbGdbServerTestCase) (test case does not fall in any category of interest for this run) 
PASS: LLDB (/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/bin/clang-arm) :: test_Hc_then_Csignal_signals_correct_thread_launch_llgs (TestLldbGdbServer.LldbGdbServerTestCase)
PASS: LLDB (/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/bin/clang-arm) :: test_Hg_fails_on_another_pid_llgs (TestLldbGdbServer.LldbGdbServerTestCase)
PASS: LLDB (/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/bin/clang-arm) :: test_Hg_fails_on_minus_one_pid_llgs (TestLldbGdbServer.LldbGdbServerTestCase)
PASS: LLDB (/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/bin/clang-arm) :: test_Hg_fails_on_zero_pid_llgs (TestLldbGdbServer.LldbGdbServerTestCase)
UNSUPPORTED: LLDB (/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/bin/clang-arm) :: test_Hg_switches_to_3_threads_launch_debugserver (TestLldbGdbServer.LldbGdbServerTestCase) (test case does not fall in any category of interest for this run) 
PASS: LLDB (/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/bin/clang-arm) :: test_Hg_switches_to_3_threads_launch_llgs (TestLldbGdbServer.LldbGdbServerTestCase)
UNSUPPORTED: LLDB (/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/bin/clang-arm) :: test_P_and_p_thread_suffix_work_debugserver (TestLldbGdbServer.LldbGdbServerTestCase) (test case does not fall in any category of interest for this run) 
PASS: LLDB (/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/bin/clang-arm) :: test_P_and_p_thread_suffix_work_llgs (TestLldbGdbServer.LldbGdbServerTestCase)
UNSUPPORTED: LLDB (/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/bin/clang-arm) :: test_P_writes_all_gpr_registers_debugserver (TestLldbGdbServer.LldbGdbServerTestCase) (test case does not fall in any category of interest for this run) 
PASS: LLDB (/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/bin/clang-arm) :: test_P_writes_all_gpr_registers_llgs (TestLldbGdbServer.LldbGdbServerTestCase)
UNSUPPORTED: LLDB (/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/bin/clang-arm) :: test_attach_commandline_continue_app_exits_debugserver (TestLldbGdbServer.LldbGdbServerTestCase) (test case does not fall in any category of interest for this run) 
Program aborted due to an unhandled Error:
Operation not permitted
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.	Program arguments: /home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/bin/lldb-server gdbserver --attach=41884 --reverse-connect [::1]:40283
#0 0x00d51d78 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/bin/lldb-server+0x331d78)
#1 0x00d4f770 llvm::sys::RunSignalHandlers() (/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/bin/lldb-server+0x32f770)
#2 0x00d52630 SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0
#3 0xf75ad6f0 __default_rt_sa_restorer ./signal/../sysdeps/unix/sysv/linux/arm/sigrestorer.S:80:0
#4 0xf759db06 ./csu/../sysdeps/unix/sysv/linux/arm/libc-do-syscall.S:47:0

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