[PATCH] D132385: [AArch64][PAC] Select XPAC for ptrauth.strip intrinsic.

Ahmed Bougacha via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 24 08:16:25 PDT 2022


This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG718bb22c2806: [AArch64][PAC] Select XPAC for ptrauth.strip intrinsic. (authored by ab).

Changed prior to commit:
  https://reviews.llvm.org/D132385?vs=456771&id=470167#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D132385/new/

https://reviews.llvm.org/D132385

Files:
  llvm/lib/Target/AArch64/AArch64InstrInfo.td
  llvm/lib/Target/AArch64/GISel/AArch64InstructionSelector.cpp
  llvm/test/CodeGen/AArch64/ptrauth-intrinsic-strip.ll


Index: llvm/test/CodeGen/AArch64/ptrauth-intrinsic-strip.ll
===================================================================
--- /dev/null
+++ llvm/test/CodeGen/AArch64/ptrauth-intrinsic-strip.ll
@@ -0,0 +1,43 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc < %s -mtriple arm64e-apple-darwin -verify-machineinstrs -global-isel=0 | FileCheck %s
+; RUN: llc < %s -mtriple arm64e-apple-darwin -verify-machineinstrs -global-isel=1 -global-isel-abort=1 | FileCheck %s
+
+target datalayout = "e-m:o-i64:64-i128:128-n32:64-S128"
+
+define i64 @test_strip_ia(i64 %arg) {
+; CHECK-LABEL: test_strip_ia:
+; CHECK:       ; %bb.0:
+; CHECK-NEXT:    xpaci x0
+; CHECK-NEXT:    ret
+  %tmp = call i64 @llvm.ptrauth.strip(i64 %arg, i32 0)
+  ret i64 %tmp
+}
+
+define i64 @test_strip_ib(i64 %arg) {
+; CHECK-LABEL: test_strip_ib:
+; CHECK:       ; %bb.0:
+; CHECK-NEXT:    xpaci x0
+; CHECK-NEXT:    ret
+  %tmp = call i64 @llvm.ptrauth.strip(i64 %arg, i32 1)
+  ret i64 %tmp
+}
+
+define i64 @test_strip_da(i64 %arg) {
+; CHECK-LABEL: test_strip_da:
+; CHECK:       ; %bb.0:
+; CHECK-NEXT:    xpacd x0
+; CHECK-NEXT:    ret
+  %tmp = call i64 @llvm.ptrauth.strip(i64 %arg, i32 2)
+  ret i64 %tmp
+}
+
+define i64 @test_strip_db(i64 %arg) {
+; CHECK-LABEL: test_strip_db:
+; CHECK:       ; %bb.0:
+; CHECK-NEXT:    xpacd x0
+; CHECK-NEXT:    ret
+  %tmp = call i64 @llvm.ptrauth.strip(i64 %arg, i32 3)
+  ret i64 %tmp
+}
+
+declare i64 @llvm.ptrauth.strip(i64, i32)
Index: llvm/lib/Target/AArch64/GISel/AArch64InstructionSelector.cpp
===================================================================
--- llvm/lib/Target/AArch64/GISel/AArch64InstructionSelector.cpp
+++ llvm/lib/Target/AArch64/GISel/AArch64InstructionSelector.cpp
@@ -5864,6 +5864,22 @@
     I.eraseFromParent();
     return true;
   }
+  case Intrinsic::ptrauth_strip: {
+    Register DstReg = I.getOperand(0).getReg();
+    Register ValReg = I.getOperand(2).getReg();
+    uint64_t Key = I.getOperand(3).getImm();
+
+    if (Key > AArch64PACKey::LAST)
+      return false;
+    unsigned Opcode = getXPACOpcodeForKey((AArch64PACKey::ID)Key);
+
+    MIB.buildInstr(Opcode, {DstReg}, {ValReg});
+
+    RBI.constrainGenericRegister(DstReg, AArch64::GPR64RegClass, MRI);
+    RBI.constrainGenericRegister(ValReg, AArch64::GPR64RegClass, MRI);
+    I.eraseFromParent();
+    return true;
+  }
   case Intrinsic::frameaddress:
   case Intrinsic::returnaddress: {
     MachineFunction &MF = *I.getParent()->getParent();
Index: llvm/lib/Target/AArch64/AArch64InstrInfo.td
===================================================================
--- llvm/lib/Target/AArch64/AArch64InstrInfo.td
+++ llvm/lib/Target/AArch64/AArch64InstrInfo.td
@@ -1361,7 +1361,12 @@
   defm AUT : SignAuth<0b001, 0b011, "aut", null_frag>;
 
   def XPACI : ClearAuth<0, "xpaci">;
+  def : Pat<(int_ptrauth_strip GPR64:$Rd, 0), (XPACI GPR64:$Rd)>;
+  def : Pat<(int_ptrauth_strip GPR64:$Rd, 1), (XPACI GPR64:$Rd)>;
+
   def XPACD : ClearAuth<1, "xpacd">;
+  def : Pat<(int_ptrauth_strip GPR64:$Rd, 2), (XPACD GPR64:$Rd)>;
+  def : Pat<(int_ptrauth_strip GPR64:$Rd, 3), (XPACD GPR64:$Rd)>;
 
   def PACGA : SignAuthTwoOperand<0b1100, "pacga", int_ptrauth_sign_generic>;
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D132385.470167.patch
Type: text/x-patch
Size: 3240 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221024/20d3d084/attachment.bin>


More information about the llvm-commits mailing list