Skip to content
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
b26f615
[AArch64] Add CodeGen support for FEAT_CPA
rgwott Aug 22, 2024
b99a0b9
Merge branch main into branch cpa
Jan 20, 2025
fb33270
[SelectionDAG] Refactor use of getMemBasePlusOffset() where applicable
rgwott Jan 20, 2025
6e491cd
[SelectionDAG] Inverted args for PTRADD on getMemBasePlusOffset()
rgwott Jan 22, 2025
eebe538
Fix minor lexical problems
rgwott Jan 22, 2025
76dae60
Satisfy undef deprecator
rgwott Jan 28, 2025
10651fa
Remove fold with unhandeable corner case
rgwott Jan 31, 2025
e64ef52
Add comment explaining removed fold for future work
rgwott Jan 31, 2025
d0b2362
Minor lexical fix
rgwott Jan 31, 2025
82d0550
Merge branch main into branch cpa
rgwott Feb 4, 2025
c70948f
Remove getMemBasePlusOffset inversion logic after #125279
rgwott Feb 4, 2025
4330997
Remove inadequate use of getMemBasePlusOffset()
rgwott Feb 4, 2025
0202b39
Remove obsolete AddedCompletixy in FEAT_CPA tablegen patterns
rgwott Feb 6, 2025
15f8b6b
Modify comment in PTRADD declaration
rgwott Feb 6, 2025
a61a19f
Gate FEAT_CPA CodeGen behind -mcpa-codegen flag
rgwott Feb 6, 2025
3a57e4d
Merge remote-tracking branch 'origin/main' into cpa
rgwott Jun 18, 2025
aec4f71
Autogenerate FEAT_CPA tests with utils/update_llc_test_checks.py
rgwott Jun 18, 2025
0935a57
Fix minor typo
rgwott Jun 18, 2025
df8a380
Fix botched merge from upstream
rgwott Jun 18, 2025
1a7982e
Fix remaining botched merge from upstream
rgwott Jun 18, 2025
d049ea5
Adapt FEAT_CPA SDAG/GISel to shouldPreservePtrArith in targetLowering
rgwott Jun 18, 2025
3e6ccee
Fix missing newline
rgwott Jun 18, 2025
b0b575b
Remove user-facing option -mcpa-codegen and use backend option instead
rgwott Jun 18, 2025
8d8cca7
Remove now-superfluous HasCPACodegen() function
rgwott Jun 18, 2025
ca45208
Remove -global-isel-abort=1 from GlobalISel tests
rgwott Jun 20, 2025
fcde60c
Insert printf() call in CPA tests to prevent case from optimizing away
rgwott Jun 20, 2025
029f1c3
Make (ADDPT|SUBPT) shift operand an i64 as opposed to i32
rgwott Jun 20, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,14 @@ cl::opt<bool> EnableSVEGISel(
cl::desc("Enable / disable SVE scalable vectors in Global ISel"),
cl::init(false));

// TODO: This option should be removed once we switch to always using PTRADD in
// the SelectionDAG.
static cl::opt<bool> UseFEATCPACodegen(
"aarch64-use-featcpa-codegen", cl::Hidden,
cl::desc("Generate ISD::PTRADD nodes for pointer arithmetic in "
"SelectionDAG for FEAT_CPA"),
cl::init(false));

/// Value type used for condition codes.
static const MVT MVT_CC = MVT::i32;

Expand Down Expand Up @@ -30416,3 +30424,8 @@ bool AArch64TargetLowering::isTypeDesirableForOp(unsigned Opc, EVT VT) const {

return TargetLowering::isTypeDesirableForOp(Opc, VT);
}

bool AArch64TargetLowering::shouldPreservePtrArith(const Function &F,
EVT VT) const {
return Subtarget->hasCPA() && UseFEATCPACodegen;
}
4 changes: 4 additions & 0 deletions llvm/lib/Target/AArch64/AArch64ISelLowering.h
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,10 @@ class AArch64TargetLowering : public TargetLowering {
/// True if stack clash protection is enabled for this functions.
bool hasInlineStackProbe(const MachineFunction &MF) const override;

/// In AArch64, true if FEAT_CPA is present. Allows pointer arithmetic
/// semantics to be preserved for instruction selection.
bool shouldPreservePtrArith(const Function &F, EVT PtrVT) const override;

private:
/// Keep a pointer to the AArch64Subtarget around so that we can
/// make the right decision when generating code for different targets.
Expand Down
15 changes: 15 additions & 0 deletions llvm/lib/Target/AArch64/AArch64InstrInfo.td
Original file line number Diff line number Diff line change
Expand Up @@ -10716,6 +10716,21 @@ let Predicates = [HasCPA] in {
// Scalar multiply-add/subtract
def MADDPT : MulAccumCPA<0, "maddpt">;
def MSUBPT : MulAccumCPA<1, "msubpt">;

def : Pat<(ptradd GPR64sp:$Rn, GPR64sp:$Rm),
(ADDPT_shift GPR64sp:$Rn, GPR64sp:$Rm, (i32 0))>;
def : Pat<(ptradd GPR64sp:$Rn, (shl GPR64sp:$Rm, (i64 imm0_7:$imm))),
(ADDPT_shift GPR64sp:$Rn, GPR64sp:$Rm,
(i32 (trunc_imm imm0_7:$imm)))>;
def : Pat<(ptradd GPR64sp:$Rn, (ineg GPR64sp:$Rm)),
(SUBPT_shift GPR64sp:$Rn, GPR64sp:$Rm, (i32 0))>;
def : Pat<(ptradd GPR64sp:$Rn, (ineg (shl GPR64sp:$Rm, (i64 imm0_7:$imm)))),
(SUBPT_shift GPR64sp:$Rn, GPR64sp:$Rm,
(i32 (trunc_imm imm0_7:$imm)))>;
def : Pat<(ptradd GPR64:$Ra, (mul GPR64:$Rn, GPR64:$Rm)),
(MADDPT GPR64:$Rn, GPR64:$Rm, GPR64:$Ra)>;
def : Pat<(ptradd GPR64:$Ra, (mul GPR64:$Rn, (ineg GPR64:$Rm))),
(MSUBPT GPR64:$Rn, GPR64:$Rm, GPR64:$Ra)>;
}

def round_v4fp32_to_v4bf16 :
Expand Down
8 changes: 7 additions & 1 deletion llvm/lib/Target/AArch64/GISel/AArch64InstructionSelector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2197,8 +2197,14 @@ bool AArch64InstructionSelector::preISelLower(MachineInstr &I) {
}
return Changed;
}
case TargetOpcode::G_PTR_ADD:
case TargetOpcode::G_PTR_ADD: {
// If Checked Pointer Arithmetic (FEAT_CPA) is present, preserve the pointer
// arithmetic semantics instead of falling back to regular arithmetic.
const auto &TL = STI.getTargetLowering();
if (TL->shouldPreservePtrArith(MF.getFunction(), EVT()))
return false;
return convertPtrAddToAdd(I, MRI);
}
case TargetOpcode::G_LOAD: {
// For scalar loads of pointers, we try to convert the dest type from p0
// to s64 so that our imported patterns can match. Like with the G_PTR_ADD
Expand Down
Loading