Skip to content

Commit d9c20e4

Browse files
authored
[AArch64][SME] Implement inline-asm clobbers for za/zt0 (llvm#79276)
This enables specifing "za" or "zt0" to the clobber list for inline asm. This complies with the acle SME addition to the asm extension here: ARM-software/acle#276
1 parent a8b5994 commit d9c20e4

File tree

5 files changed

+44
-1
lines changed

5 files changed

+44
-1
lines changed

clang/lib/Basic/Targets/AArch64.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1174,6 +1174,8 @@ TargetInfo::BuiltinVaListKind AArch64TargetInfo::getBuiltinVaListKind() const {
11741174
}
11751175

11761176
const char *const AArch64TargetInfo::GCCRegNames[] = {
1177+
// clang-format off
1178+
11771179
// 32-bit Integer registers
11781180
"w0", "w1", "w2", "w3", "w4", "w5", "w6", "w7", "w8", "w9", "w10", "w11",
11791181
"w12", "w13", "w14", "w15", "w16", "w17", "w18", "w19", "w20", "w21", "w22",
@@ -1210,7 +1212,12 @@ const char *const AArch64TargetInfo::GCCRegNames[] = {
12101212

12111213
// SVE predicate-as-counter registers
12121214
"pn0", "pn1", "pn2", "pn3", "pn4", "pn5", "pn6", "pn7", "pn8",
1213-
"pn9", "pn10", "pn11", "pn12", "pn13", "pn14", "pn15"
1215+
"pn9", "pn10", "pn11", "pn12", "pn13", "pn14", "pn15",
1216+
1217+
// SME registers
1218+
"za", "zt0",
1219+
1220+
// clang-format on
12141221
};
12151222

12161223
ArrayRef<const char *> AArch64TargetInfo::getGCCRegNames() const {

clang/test/CodeGen/aarch64-inline-asm.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,11 @@ void test_reduced_gpr_constraints(int var32, long var64) {
9595
// CHECK: [[ARG2:%.+]] = load i64, ptr
9696
// CHECK: call void asm sideeffect "add x0, x0, $0", "@3Ucj,~{x0}"(i64 [[ARG2]])
9797
}
98+
99+
void test_sme_constraints(){
100+
asm("movt zt0[3, mul vl], z0" : : : "za");
101+
// CHECK: call void asm sideeffect "movt zt0[3, mul vl], z0", "~{za}"()
102+
103+
asm("movt zt0[3, mul vl], z0" : : : "zt0");
104+
// CHECK: call void asm sideeffect "movt zt0[3, mul vl], z0", "~{zt0}"()
105+
}

llvm/lib/Target/AArch64/AArch64ISelLowering.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10728,6 +10728,14 @@ AArch64TargetLowering::getRegForInlineAsmConstraint(
1072810728
parseConstraintCode(Constraint) != AArch64CC::Invalid)
1072910729
return std::make_pair(unsigned(AArch64::NZCV), &AArch64::CCRRegClass);
1073010730

10731+
if (Constraint == "{za}") {
10732+
return std::make_pair(unsigned(AArch64::ZA), &AArch64::MPRRegClass);
10733+
}
10734+
10735+
if (Constraint == "{zt0}") {
10736+
return std::make_pair(unsigned(AArch64::ZT0), &AArch64::ZTRRegClass);
10737+
}
10738+
1073110739
// Use the default implementation in TargetLowering to convert the register
1073210740
// constraint into a member of a register class.
1073310741
std::pair<unsigned, const TargetRegisterClass *> Res;

llvm/lib/Target/AArch64/AArch64RegisterInfo.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,10 @@ bool AArch64RegisterInfo::isAsmClobberable(const MachineFunction &MF,
507507
MCRegisterInfo::regsOverlap(PhysReg, AArch64::X16))
508508
return true;
509509

510+
// ZA/ZT0 registers are reserved but may be permitted in the clobber list.
511+
if (PhysReg == AArch64::ZA || PhysReg == AArch64::ZT0)
512+
return true;
513+
510514
return !isReservedReg(MF, PhysReg);
511515
}
512516

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2+
; RUN: llc -mtriple=aarch64-none-linux-gnu -stop-after=aarch64-isel < %s -o - | FileCheck %s
3+
4+
define void @alpha(<vscale x 4 x i32> %x) local_unnamed_addr {
5+
entry:
6+
; CHECK: INLINEASM &"movt zt0[3, mul vl], z0", 1 /* sideeffect attdialect */, 12 /* clobber */, implicit-def early-clobber $za
7+
tail call void asm sideeffect "movt zt0[3, mul vl], z0", "~{za}"()
8+
ret void
9+
}
10+
11+
define void @beta(<vscale x 4 x i32> %x) local_unnamed_addr {
12+
entry:
13+
; CHECK: INLINEASM &"movt zt0[3, mul vl], z0", 1 /* sideeffect attdialect */, 12 /* clobber */, implicit-def early-clobber $zt0
14+
tail call void asm sideeffect "movt zt0[3, mul vl], z0", "~{zt0}"()
15+
ret void
16+
}

0 commit comments

Comments
 (0)