[llvm] [AArch64][MachineOutliner] Allow calls to be outlined when PAC is enabled (PR #230840)

via llvm-commits llvm-commits at lists.llvm.org
Sun Oct 11 19:21:51 PDT 2026


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff origin/main HEAD --extensions cpp -- llvm/lib/Target/AArch64/AArch64InstrInfo.cpp --diff_from_common_commit
``````````

:warning:
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing `origin/main` to the base branch/commit you want to compare against.
:warning:

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/llvm/lib/Target/AArch64/AArch64InstrInfo.cpp b/llvm/lib/Target/AArch64/AArch64InstrInfo.cpp
index 5ad936f22..17c6871a1 100644
--- a/llvm/lib/Target/AArch64/AArch64InstrInfo.cpp
+++ b/llvm/lib/Target/AArch64/AArch64InstrInfo.cpp
@@ -10847,62 +10847,64 @@ AArch64InstrInfo::getOutliningCandidateInfo(
              FrameID != MachineOutlinerTailCall && FirstCand.back().isCall())
       ModStackToSaveLR = true;
 
-   if (ModStackToSaveLR) {
-  // We can't fix up the stack. Bail out.
-  if (!AllStackInstrsSafe)
-    return std::nullopt;
+    if (ModStackToSaveLR) {
+      // We can't fix up the stack. Bail out.
+      if (!AllStackInstrsSafe)
+        return std::nullopt;
 
-  // If PAC is enabled, ensure SP modifications are balanced.
-  // PAC-RET thunks use SP as the cryptographic context.
-  auto LRCheckMethod = Subtarget.getAuthenticatedLRCheckMethod(*RepeatedSequenceLocs[0].getMF());
-  if (AArch64PAuth::getCheckerSizeInBytes(LRCheckMethod) > 0) {
-    auto hasIllegalSPModification = [&TRI](outliner::Candidate &C) {
-      int SPValue = 0;
-      for (auto &MI : C) {
-        if (MI.modifiesRegister(AArch64::SP, &TRI)) {
-          switch (MI.getOpcode()) {
-          case AArch64::ADDXri:
-          case AArch64::ADDWri:
-            assert(MI.getNumOperands() == 4 && "Wrong number of operands");
-            assert(MI.getOperand(2).isImm() &&
-                   "Expected operand to be immediate");
-            assert(MI.getOperand(1).isReg() &&
-                   "Expected operand to be a register");
-            if (MI.getOperand(1).getReg() == AArch64::SP)
-              SPValue += MI.getOperand(2).getImm();
-            else
-              return true;
-            break;
-          case AArch64::SUBXri:
-          case AArch64::SUBWri:
-            assert(MI.getNumOperands() == 4 && "Wrong number of operands");
-            assert(MI.getOperand(2).isImm() &&
-                   "Expected operand to be immediate");
-            assert(MI.getOperand(1).isReg() &&
-                   "Expected operand to be a register");
-            if (MI.getOperand(1).getReg() == AArch64::SP)
-              SPValue -= MI.getOperand(2).getImm();
-            else
-              return true;
-            break;
-          default:
-            return true;
+      // If PAC is enabled, ensure SP modifications are balanced.
+      // PAC-RET thunks use SP as the cryptographic context.
+      auto LRCheckMethod = Subtarget.getAuthenticatedLRCheckMethod(
+          *RepeatedSequenceLocs[0].getMF());
+      if (AArch64PAuth::getCheckerSizeInBytes(LRCheckMethod) > 0) {
+        auto hasIllegalSPModification = [&TRI](outliner::Candidate &C) {
+          int SPValue = 0;
+          for (auto &MI : C) {
+            if (MI.modifiesRegister(AArch64::SP, &TRI)) {
+              switch (MI.getOpcode()) {
+              case AArch64::ADDXri:
+              case AArch64::ADDWri:
+                assert(MI.getNumOperands() == 4 && "Wrong number of operands");
+                assert(MI.getOperand(2).isImm() &&
+                       "Expected operand to be immediate");
+                assert(MI.getOperand(1).isReg() &&
+                       "Expected operand to be a register");
+                if (MI.getOperand(1).getReg() == AArch64::SP)
+                  SPValue += MI.getOperand(2).getImm();
+                else
+                  return true;
+                break;
+              case AArch64::SUBXri:
+              case AArch64::SUBWri:
+                assert(MI.getNumOperands() == 4 && "Wrong number of operands");
+                assert(MI.getOperand(2).isImm() &&
+                       "Expected operand to be immediate");
+                assert(MI.getOperand(1).isReg() &&
+                       "Expected operand to be a register");
+                if (MI.getOperand(1).getReg() == AArch64::SP)
+                  SPValue -= MI.getOperand(2).getImm();
+                else
+                  return true;
+                break;
+              default:
+                return true;
+              }
+            }
           }
-        }
-      }
-      if (SPValue)
-        return true;
-      return false;
-    };
+          if (SPValue)
+            return true;
+          return false;
+        };
 
-    // All candidates share the exact same instruction sequence.
-    // If the first candidate modifies SP illegally, the whole sequence is invalid.
-    if (hasIllegalSPModification(RepeatedSequenceLocs[0]))
-      return std::nullopt;
-  }
+        // All candidates share the exact same instruction sequence.
+        // If the first candidate modifies SP illegally, the whole sequence is
+        // invalid.
+        if (hasIllegalSPModification(RepeatedSequenceLocs[0]))
+          return std::nullopt;
+      }
 
-  // Save + restore LR.
-  NumBytesToCreateFrame += 8;
+      // Save + restore LR.
+      NumBytesToCreateFrame += 8;
 
       // Add the extra mov if we will save a frame record instead of just LR.
       if (predictCompactUnwindFrameRecordForOutlinedFunction(

``````````

</details>


https://github.com/llvm/llvm-project/pull/230840


More information about the llvm-commits mailing list