[llvm] [AArch64][PAC] Expand blend(reg, imm) operation in aarch64-pauth pass (PR #74729)
Anton Korobeynikov via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 31 15:37:22 PST 2024
https://github.com/asl updated https://github.com/llvm/llvm-project/pull/74729
>From 57e15499a36764af635863ab9251fe70e0801f8c Mon Sep 17 00:00:00 2001
From: Anatoly Trosinenko <atrosinenko at accesssoftek.com>
Date: Wed, 29 Nov 2023 17:35:02 +0300
Subject: [PATCH] [AArch64][PAC] Expand blend(reg, imm) operation in
aarch64-pauth pass
In preparation for implementing code generation for more @llvm.ptrauth.*
intrinsics, move the expansion of blend(register, small integer) variant
of @llvm.ptrauth.blend to the AArch64PointerAuth pass, where most other
PAuth-related code generation takes place.
---
llvm/lib/Target/AArch64/AArch64InstrInfo.td | 7 ++--
.../lib/Target/AArch64/AArch64PointerAuth.cpp | 37 +++++++++++++++++++
2 files changed, 41 insertions(+), 3 deletions(-)
diff --git a/llvm/lib/Target/AArch64/AArch64InstrInfo.td b/llvm/lib/Target/AArch64/AArch64InstrInfo.td
index 6beacea31cb00..6018d662fe514 100644
--- a/llvm/lib/Target/AArch64/AArch64InstrInfo.td
+++ b/llvm/lib/Target/AArch64/AArch64InstrInfo.td
@@ -1581,6 +1581,9 @@ 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 {
@@ -9317,12 +9320,10 @@ let Predicates = [HasMOPS, HasMTE], Defs = [NZCV], Size = 12, mayLoad = 0, maySt
//-----------------------------------------------------------------------------
// v8.3 Pointer Authentication late patterns
-let Predicates = [HasPAuth] in {
def : Pat<(int_ptrauth_blend GPR64:$Rd, imm64_0_65535:$imm),
- (MOVKXi GPR64:$Rd, (trunc_imm imm64_0_65535:$imm), 48)>;
+ (PAUTH_BLEND GPR64:$Rd, (trunc_imm imm64_0_65535:$imm))>;
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 7509afaeb5fef..d8a2853f68e02 100644
--- a/llvm/lib/Target/AArch64/AArch64PointerAuth.cpp
+++ b/llvm/lib/Target/AArch64/AArch64PointerAuth.cpp
@@ -46,6 +46,13 @@ class AArch64PointerAuth : public MachineFunctionPass {
void authenticateLR(MachineFunction &MF,
MachineBasicBlock::iterator MBBI) const;
+ /// Stores blend(AddrDisc, IntDisc) to the Result register.
+ 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;
};
@@ -359,6 +366,32 @@ bool AArch64PointerAuth::checkAuthenticatedLR(
return true;
}
+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) {
const auto *MFnI = MF.getInfo<AArch64FunctionInfo>();
@@ -390,6 +423,7 @@ bool AArch64PointerAuth::runOnMachineFunction(MachineFunction &MF) {
break;
case AArch64::PAUTH_PROLOGUE:
case AArch64::PAUTH_EPILOGUE:
+ case AArch64::PAUTH_BLEND:
assert(!MI.isBundled());
PAuthPseudoInstrs.push_back(MI.getIterator());
break;
@@ -406,6 +440,9 @@ bool AArch64PointerAuth::runOnMachineFunction(MachineFunction &MF) {
authenticateLR(MF, It);
HasAuthenticationInstrs = true;
break;
+ case AArch64::PAUTH_BLEND:
+ expandPAuthBlend(It);
+ break;
default:
llvm_unreachable("Unhandled opcode");
}
More information about the llvm-commits
mailing list