Skip to content

Commit 3b1d34a

Browse files
committed
[AArch64][SME2] Add ldr_zt, str_zt builtins and intrinsics
1 parent 761a963 commit 3b1d34a

File tree

9 files changed

+140
-9
lines changed

9 files changed

+140
-9
lines changed

clang/include/clang/Basic/arm_sme.td

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,3 +298,11 @@ multiclass ZAAddSub<string n_suffix> {
298298

299299
defm SVADD : ZAAddSub<"add">;
300300
defm SVSUB : ZAAddSub<"sub">;
301+
302+
//
303+
// Spill and fill of ZT0
304+
//
305+
let TargetGuard = "sme2" in {
306+
def SVLDR_ZT : Inst<"svldr_zt", "viQ", "", MergeNone, "aarch64_sme_ldr_zt", [IsOverloadNone, IsStreamingCompatible, IsSharedZA, IsPreservesZA], [ImmCheck<0, ImmCheck0_0>]>;
307+
def SVSTR_ZT : Inst<"svstr_zt", "vi%", "", MergeNone, "aarch64_sme_str_zt", [IsOverloadNone, IsStreamingCompatible, IsSharedZA, IsPreservesZA], [ImmCheck<0, ImmCheck0_0>]>;
308+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
2+
3+
// REQUIRES: aarch64-registered-target
4+
5+
// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme2 -S -disable-O0-optnone -Werror -Wall -emit-llvm -o - %s | opt -S -p mem2reg,instcombine,tailcallelim | FileCheck %s
6+
// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme2 -S -disable-O0-optnone -Werror -Wall -emit-llvm -o - -x c++ %s | opt -S -p mem2reg,instcombine,tailcallelim | FileCheck %s -check-prefix=CPP-CHECK
7+
// RUN: %clang_cc1 -DSVE_OVERLOADED_FORMS -triple aarch64-none-linux-gnu -target-feature +sme2 -S -disable-O0-optnone -Werror -Wall -emit-llvm -o - %s | opt -S -p mem2reg,instcombine,tailcallelim | FileCheck %s
8+
// RUN: %clang_cc1 -DSVE_OVERLOADED_FORMS -triple aarch64-none-linux-gnu -target-feature +sme2 -S -disable-O0-optnone -Werror -Wall -emit-llvm -o - -x c++ %s | opt -S -p mem2reg,instcombine,tailcallelim | FileCheck %s -check-prefix=CPP-CHECK
9+
// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme2 -S -disable-O0-optnone -Werror -Wall -o /dev/null %s
10+
11+
#include <arm_sme_draft_spec_subject_to_change.h>
12+
13+
#ifdef SVE_OVERLOADED_FORMS
14+
// A simple used,unused... macro, long enough to represent any SVE builtin.
15+
#define SVE_ACLE_FUNC(A1,A2_UNUSED) A1
16+
#else
17+
#define SVE_ACLE_FUNC(A1,A2) A1##A2
18+
#endif
19+
20+
// LDR ZT0
21+
22+
// CHECK-LABEL: @test_svldr_zt(
23+
// CHECK-NEXT: entry:
24+
// CHECK-NEXT: tail call void @llvm.aarch64.sme.ldr.zt(i32 0, ptr [[BASE:%.*]])
25+
// CHECK-NEXT: ret void
26+
//
27+
// CPP-CHECK-LABEL: @_Z13test_svldr_ztPKv(
28+
// CPP-CHECK-NEXT: entry:
29+
// CPP-CHECK-NEXT: tail call void @llvm.aarch64.sme.ldr.zt(i32 0, ptr [[BASE:%.*]])
30+
// CPP-CHECK-NEXT: ret void
31+
//
32+
void test_svldr_zt(const void *base) __arm_streaming_compatible __arm_shared_za __arm_preserves_za {
33+
svldr_zt(0, base);
34+
} ;
35+
36+
37+
// STR ZT0
38+
39+
// CHECK-LABEL: @test_svstr_zt(
40+
// CHECK-NEXT: entry:
41+
// CHECK-NEXT: tail call void @llvm.aarch64.sme.str.zt(i32 0, ptr [[BASE:%.*]])
42+
// CHECK-NEXT: ret void
43+
//
44+
// CPP-CHECK-LABEL: @_Z13test_svstr_ztPv(
45+
// CPP-CHECK-NEXT: entry:
46+
// CPP-CHECK-NEXT: tail call void @llvm.aarch64.sme.str.zt(i32 0, ptr [[BASE:%.*]])
47+
// CPP-CHECK-NEXT: ret void
48+
//
49+
void test_svstr_zt(void *base) __arm_streaming_compatible __arm_shared_za __arm_preserves_za {
50+
svstr_zt(0, base);
51+
}

llvm/lib/Target/AArch64/AArch64ISelDAGToDAG.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,15 +326,19 @@ class AArch64DAGToDAGISel : public SelectionDAGISel {
326326
return false;
327327
}
328328

329-
template <unsigned BaseReg> bool ImmToTile(SDValue N, SDValue &Imm) {
329+
template <unsigned BaseReg, unsigned Max>
330+
bool ImmToTile(SDValue N, SDValue &Imm) {
330331
if (auto *CI = dyn_cast<ConstantSDNode>(N)) {
331332
uint64_t C = CI->getZExtValue();
333+
334+
if (C > Max)
335+
return false;
336+
332337
Imm = CurDAG->getRegister(BaseReg + C, MVT::Other);
333338
return true;
334339
}
335340
return false;
336341
}
337-
338342
/// Form sequences of consecutive 64/128-bit registers for use in NEON
339343
/// instructions making use of a vector-list (e.g. ldN, tbl). Vecs must have
340344
/// between 1 and 4 elements. If it contains a single element that is returned

llvm/lib/Target/AArch64/AArch64ISelLowering.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2748,6 +2748,22 @@ AArch64TargetLowering::EmitFill(MachineInstr &MI, MachineBasicBlock *BB) const {
27482748
return BB;
27492749
}
27502750

2751+
MachineBasicBlock *AArch64TargetLowering::EmitZTSpillFill(MachineInstr &MI,
2752+
MachineBasicBlock *BB,
2753+
bool IsSpill) const {
2754+
const TargetInstrInfo *TII = Subtarget->getInstrInfo();
2755+
MachineInstrBuilder MIB;
2756+
if (IsSpill) {
2757+
MIB = BuildMI(*BB, MI, MI.getDebugLoc(), TII->get(AArch64::STR_TX));
2758+
MIB.addReg(MI.getOperand(0).getReg());
2759+
} else
2760+
MIB = BuildMI(*BB, MI, MI.getDebugLoc(), TII->get(AArch64::LDR_TX),
2761+
MI.getOperand(0).getReg());
2762+
MIB.add(MI.getOperand(1)); // Base
2763+
MI.eraseFromParent(); // The pseudo is gone now.
2764+
return BB;
2765+
}
2766+
27512767
MachineBasicBlock *
27522768
AArch64TargetLowering::EmitZAInstr(unsigned Opc, unsigned BaseReg,
27532769
MachineInstr &MI,
@@ -2864,6 +2880,10 @@ MachineBasicBlock *AArch64TargetLowering::EmitInstrWithCustomInserter(
28642880
return EmitTileLoad(AArch64::LD1_MXIPXX_V_Q, AArch64::ZAQ0, MI, BB);
28652881
case AArch64::LDR_ZA_PSEUDO:
28662882
return EmitFill(MI, BB);
2883+
case AArch64::LDR_TX_PSEUDO:
2884+
return EmitZTSpillFill(MI, BB, /*IsSpill=*/false);
2885+
case AArch64::STR_TX_PSEUDO:
2886+
return EmitZTSpillFill(MI, BB, /*IsSpill=*/true);
28672887
case AArch64::ZERO_M_PSEUDO:
28682888
return EmitZero(MI, BB);
28692889
}

llvm/lib/Target/AArch64/AArch64ISelLowering.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,8 @@ class AArch64TargetLowering : public TargetLowering {
612612
MachineBasicBlock *EmitZAInstr(unsigned Opc, unsigned BaseReg,
613613
MachineInstr &MI, MachineBasicBlock *BB,
614614
bool HasTile) const;
615+
MachineBasicBlock *EmitZTSpillFill(MachineInstr &MI, MachineBasicBlock *BB,
616+
bool IsSpill) const;
615617
MachineBasicBlock *EmitZero(MachineInstr &MI, MachineBasicBlock *BB) const;
616618

617619
MachineBasicBlock *

llvm/lib/Target/AArch64/AArch64RegisterInfo.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,12 @@ AArch64RegisterInfo::getStrictlyReservedRegs(const MachineFunction &MF) const {
440440
Reserved.set(SubReg);
441441
}
442442

443+
if (MF.getSubtarget<AArch64Subtarget>().hasSME2()) {
444+
for (MCSubRegIterator SubReg(AArch64::ZT0, this, /*self=*/true);
445+
SubReg.isValid(); ++SubReg)
446+
Reserved.set(*SubReg);
447+
}
448+
443449
markSuperRegs(Reserved, AArch64::FPCR);
444450

445451
if (MF.getFunction().getCallingConv() == CallingConv::GRAAL) {

llvm/lib/Target/AArch64/AArch64SMEInstrInfo.td

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -541,8 +541,8 @@ defm UMOPS_MPPZZ_HtoS : sme2_int_mopx_tile<"umops", 0b101, int_aarch64_sme_umops
541541

542542
def ZERO_T : sme2_zero_zt<"zero", 0b0001>;
543543

544-
def LDR_TX : sme2_spill_fill_vector<"ldr", 0b01111100>;
545-
def STR_TX : sme2_spill_fill_vector<"str", 0b11111100>;
544+
defm LDR_TX : sme2_spill_fill_vector<"ldr", 0b01111100, int_aarch64_sme_ldr_zt>;
545+
defm STR_TX : sme2_spill_fill_vector<"str", 0b11111100, int_aarch64_sme_str_zt>;
546546

547547
def MOVT_XTI : sme2_movt_zt_to_scalar<"movt", 0b0011111>;
548548
def MOVT_TIX : sme2_movt_scalar_to_zt<"movt", 0b0011111>;

llvm/lib/Target/AArch64/SMEInstrFormats.td

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
def imm_to_tile8 : ComplexPattern<i32, 1, "ImmToTile<AArch64::ZAB0>", []>;
14-
def imm_to_tile16 : ComplexPattern<i32, 1, "ImmToTile<AArch64::ZAH0>", []>;
15-
def imm_to_tile32 : ComplexPattern<i32, 1, "ImmToTile<AArch64::ZAS0>", []>;
16-
def imm_to_tile64 : ComplexPattern<i32, 1, "ImmToTile<AArch64::ZAD0>", []>;
17-
def imm_to_tile128 : ComplexPattern<i32, 1, "ImmToTile<AArch64::ZAQ0>", []>;
13+
def imm_to_tile8 : ComplexPattern<i32, 1, "ImmToTile<AArch64::ZAB0, 0>", []>;
14+
def imm_to_tile16 : ComplexPattern<i32, 1, "ImmToTile<AArch64::ZAH0, 1>", []>;
15+
def imm_to_tile32 : ComplexPattern<i32, 1, "ImmToTile<AArch64::ZAS0, 3>", []>;
16+
def imm_to_tile64 : ComplexPattern<i32, 1, "ImmToTile<AArch64::ZAD0, 7>", []>;
17+
def imm_to_tile128 : ComplexPattern<i32, 1, "ImmToTile<AArch64::ZAQ0, 15>", []>;
18+
def imm_to_zt : ComplexPattern<i32, 1, "ImmToTile<AArch64::ZT0, 0>", []>;
1819

1920
def tileslice8 : ComplexPattern<i32 , 2, "SelectSMETileSlice<15, 1>", []>;
2021
def tileslice16 : ComplexPattern<i32 , 2, "SelectSMETileSlice<7, 1>", []>;
@@ -3137,6 +3138,18 @@ class sme2_spill_fill_vector<string mnemonic, bits<8> opc>
31373138
let mayStore = opc{7};
31383139
}
31393140

3141+
3142+
multiclass sme2_spill_fill_vector<string mnemonic, bits<8> opc, SDPatternOperator op> {
3143+
def NAME : sme2_spill_fill_vector<mnemonic, opc>;
3144+
def NAME # _PSEUDO
3145+
: Pseudo<(outs), (ins ZTR:$ZTt, GPR64sp:$base), []>, Sched<[]> {
3146+
// Translated to actual instruction in AArch64ISelLowering.cpp
3147+
let usesCustomInserter = 1;
3148+
}
3149+
def : Pat<(op (imm_to_zt untyped:$tile), GPR64sp:$base),
3150+
(!cast<Instruction>(NAME # _PSEUDO) $tile, $base)>;
3151+
}
3152+
31403153
//===----------------------------------------------------------------------===///
31413154
// SME2 move to/from lookup table
31423155
class sme2_movt_zt_to_scalar<string mnemonic, bits<7> opc>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2+
; RUN: llc -mtriple=aarch64-linux-gnu -mattr=+sme2 -verify-machineinstrs < %s | FileCheck %s
3+
4+
; LDR
5+
6+
define void @ldr_zt0(ptr %ptr) {
7+
; CHECK-LABEL: ldr_zt0:
8+
; CHECK: // %bb.0:
9+
; CHECK-NEXT: ldr zt0, [x0]
10+
; CHECK-NEXT: ret
11+
call void @llvm.aarch64.sme.ldr.zt(i32 0, ptr %ptr)
12+
ret void;
13+
}
14+
15+
; STR
16+
17+
define void @str_zt0(ptr %ptr) {
18+
; CHECK-LABEL: str_zt0:
19+
; CHECK: // %bb.0:
20+
; CHECK-NEXT: str zt0, [x0]
21+
; CHECK-NEXT: ret
22+
call void @llvm.aarch64.sme.str.zt(i32 0, ptr %ptr)
23+
ret void;
24+
}
25+
26+
declare void @llvm.aarch64.sme.ldr.zt(i32, ptr)
27+
declare void @llvm.aarch64.sme.str.zt(i32, ptr)

0 commit comments

Comments
 (0)