Skip to content

Commit

Permalink
[AArch64][PAC] Select XPAC for ptrauth.strip intrinsic.
Browse files Browse the repository at this point in the history
Differential Revision: https://reviews.llvm.org/D132385
  • Loading branch information
ahmedbougacha committed Oct 24, 2022
1 parent 5b70001 commit 718bb22
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 0 deletions.
5 changes: 5 additions & 0 deletions llvm/lib/Target/AArch64/AArch64InstrInfo.td
Expand Up @@ -1361,7 +1361,12 @@ let Predicates = [HasPAuth] in {
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>;

Expand Down
16 changes: 16 additions & 0 deletions llvm/lib/Target/AArch64/GISel/AArch64InstructionSelector.cpp
Expand Up @@ -5864,6 +5864,22 @@ bool AArch64InstructionSelector::selectIntrinsic(MachineInstr &I,
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();
Expand Down
43 changes: 43 additions & 0 deletions 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)

0 comments on commit 718bb22

Please sign in to comment.