Skip to content

AArch64: Remove the PAUTH_BLEND pseudo-instruction. #134765

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

pcc
Copy link
Contributor

@pcc pcc commented Apr 8, 2025

It can be represented using a regular MOVK instruction
which also has the advantage of sometimes being selectable
without a preceding MOV.

Created using spr 1.3.6-beta.1
@llvmbot
Copy link
Member

llvmbot commented Apr 8, 2025

@llvm/pr-subscribers-backend-aarch64

Author: Peter Collingbourne (pcc)

Changes

It can be represented using a regular MOVK instruction
which also has the advantage of sometimes being selectable
without a preceding MOV.


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

3 Files Affected:

  • (modified) llvm/lib/Target/AArch64/AArch64InstrInfo.td (+1-4)
  • (modified) llvm/lib/Target/AArch64/AArch64PointerAuth.cpp (-33)
  • (removed) llvm/test/CodeGen/AArch64/ptrauth-pseudo-instructions.mir (-27)
diff --git a/llvm/lib/Target/AArch64/AArch64InstrInfo.td b/llvm/lib/Target/AArch64/AArch64InstrInfo.td
index a2d98a0862988..7307d412694a1 100644
--- a/llvm/lib/Target/AArch64/AArch64InstrInfo.td
+++ b/llvm/lib/Target/AArch64/AArch64InstrInfo.td
@@ -1798,9 +1798,6 @@ def PAUTH_PROLOGUE : Pseudo<(outs), (ins), []>, Sched<[]> {
 def PAUTH_EPILOGUE : Pseudo<(outs), (ins), []>, Sched<[]>;
 }
 
-def PAUTH_BLEND : Pseudo<(outs GPR64:$disc),
-                         (ins GPR64:$addr_disc, i32imm:$int_disc), []>, Sched<[]>;
-
 // These pointer authentication instructions require armv8.3a
 let Predicates = [HasPAuth] in {
 
@@ -10136,7 +10133,7 @@ let Predicates = [HasMOPS, HasMTE], Defs = [NZCV], Size = 12, mayLoad = 0, maySt
 // v8.3 Pointer Authentication late patterns
 
 def : Pat<(int_ptrauth_blend GPR64:$Rd, imm64_0_65535:$imm),
-          (PAUTH_BLEND GPR64:$Rd, (trunc_imm imm64_0_65535:$imm))>;
+          (MOVKXi GPR64:$Rd, (trunc_imm imm64_0_65535:$imm), 48)>;
 def : Pat<(int_ptrauth_blend GPR64:$Rd, GPR64:$Rn),
           (BFMXri GPR64:$Rd, GPR64:$Rn, 16, 15)>;
 
diff --git a/llvm/lib/Target/AArch64/AArch64PointerAuth.cpp b/llvm/lib/Target/AArch64/AArch64PointerAuth.cpp
index c3bc70ad6f427..13a36551c207c 100644
--- a/llvm/lib/Target/AArch64/AArch64PointerAuth.cpp
+++ b/llvm/lib/Target/AArch64/AArch64PointerAuth.cpp
@@ -46,9 +46,6 @@ class AArch64PointerAuth : public MachineFunctionPass {
   void emitBlend(MachineBasicBlock::iterator MBBI, Register Result,
                  Register AddrDisc, unsigned IntDisc) const;
 
-  /// Expands PAUTH_BLEND pseudo instruction.
-  void expandPAuthBlend(MachineBasicBlock::iterator MBBI) const;
-
   bool checkAuthenticatedLR(MachineBasicBlock::iterator TI) const;
 };
 
@@ -249,32 +246,6 @@ unsigned llvm::AArch64PAuth::getCheckerSizeInBytes(AuthCheckMethod Method) {
   llvm_unreachable("Unknown AuthCheckMethod enum");
 }
 
-void AArch64PointerAuth::emitBlend(MachineBasicBlock::iterator MBBI,
-                                   Register Result, Register AddrDisc,
-                                   unsigned IntDisc) const {
-  MachineBasicBlock &MBB = *MBBI->getParent();
-  DebugLoc DL = MBBI->getDebugLoc();
-
-  if (Result != AddrDisc)
-    BuildMI(MBB, MBBI, DL, TII->get(AArch64::ORRXrs), Result)
-        .addReg(AArch64::XZR)
-        .addReg(AddrDisc)
-        .addImm(0);
-
-  BuildMI(MBB, MBBI, DL, TII->get(AArch64::MOVKXi), Result)
-      .addReg(Result)
-      .addImm(IntDisc)
-      .addImm(48);
-}
-
-void AArch64PointerAuth::expandPAuthBlend(
-    MachineBasicBlock::iterator MBBI) const {
-  Register ResultReg = MBBI->getOperand(0).getReg();
-  Register AddrDisc = MBBI->getOperand(1).getReg();
-  unsigned IntDisc = MBBI->getOperand(2).getImm();
-  emitBlend(MBBI, ResultReg, AddrDisc, IntDisc);
-}
-
 bool AArch64PointerAuth::runOnMachineFunction(MachineFunction &MF) {
   Subtarget = &MF.getSubtarget<AArch64Subtarget>();
   TII = Subtarget->getInstrInfo();
@@ -290,7 +261,6 @@ bool AArch64PointerAuth::runOnMachineFunction(MachineFunction &MF) {
         break;
       case AArch64::PAUTH_PROLOGUE:
       case AArch64::PAUTH_EPILOGUE:
-      case AArch64::PAUTH_BLEND:
         PAuthPseudoInstrs.push_back(MI.getIterator());
         break;
       }
@@ -305,9 +275,6 @@ bool AArch64PointerAuth::runOnMachineFunction(MachineFunction &MF) {
     case AArch64::PAUTH_EPILOGUE:
       authenticateLR(MF, It);
       break;
-    case AArch64::PAUTH_BLEND:
-      expandPAuthBlend(It);
-      break;
     default:
       llvm_unreachable("Unhandled opcode");
     }
diff --git a/llvm/test/CodeGen/AArch64/ptrauth-pseudo-instructions.mir b/llvm/test/CodeGen/AArch64/ptrauth-pseudo-instructions.mir
deleted file mode 100644
index d7fe1953deb47..0000000000000
--- a/llvm/test/CodeGen/AArch64/ptrauth-pseudo-instructions.mir
+++ /dev/null
@@ -1,27 +0,0 @@
-# RUN: llc -mtriple=aarch64--- -run-pass=aarch64-ptrauth -verify-machineinstrs %s -o - | FileCheck %s
-
-# Test the corner cases that cannot be reliably tested using LLVM IR as input.
-
---- |
-  define i64 @blend_untied(i64 %unused, i64 %ptr_arg) {
-    ret i64 0
-  }
-...
----
-# Check that the input register is copied to the output one, if not tied.
-
-name:            blend_untied
-tracksRegLiveness: true
-body:             |
-  bb.0:
-  liveins: $lr, $x0, $x1
-    $x0 = PAUTH_BLEND $x1, 42
-    RET undef $lr
-
-# CHECK:       liveins: $lr, $x0, $x1
-# CHECK-NEXT:    {{^ +$}}
-# CHECK-NEXT:    $x0 = ORRXrs $xzr, $x1, 0
-# CHECK-NEXT:    $x0 = MOVKXi $x0, 42, 48
-# CHECK-NEXT:    RET undef $lr
-
-...

pcc added a commit that referenced this pull request Apr 8, 2025
Created using spr 1.3.6-beta.1
@pcc pcc requested review from atrosinenko, asl and ahmedbougacha April 8, 2025 01:29
Created using spr 1.3.6-beta.1
pcc added 2 commits April 9, 2025 20:17
Created using spr 1.3.6-beta.1
Created using spr 1.3.6-beta.1
Copy link
Contributor

@atrosinenko atrosinenko left a comment

Choose a reason for hiding this comment

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

LGTM with a trivial nitpick.

Comment on lines 46 to 48
void emitBlend(MachineBasicBlock::iterator MBBI, Register Result,
Register AddrDisc, unsigned IntDisc) const;

Copy link
Contributor

Choose a reason for hiding this comment

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

[nit] This function was removed as well.

Created using spr 1.3.6-beta.1
@pcc pcc merged commit 3f58ff2 into main Apr 15, 2025
5 of 9 checks passed
@pcc pcc deleted the users/pcc/spr/aarch64-remove-the-pauth_blend-pseudo-instruction branch April 15, 2025 18:08
llvm-sync bot pushed a commit to arm/arm-toolchain that referenced this pull request Apr 15, 2025
It can be represented using a regular MOVK instruction
which also has the advantage of sometimes being selectable
without a preceding MOV.

Reviewers: ahmedbougacha, asl, atrosinenko

Reviewed By: atrosinenko

Pull Request: llvm/llvm-project#134765
var-const pushed a commit to ldionne/llvm-project that referenced this pull request Apr 17, 2025
It can be represented using a regular MOVK instruction
which also has the advantage of sometimes being selectable
without a preceding MOV.

Reviewers: ahmedbougacha, asl, atrosinenko

Reviewed By: atrosinenko

Pull Request: llvm#134765
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

Successfully merging this pull request may close these issues.

3 participants