Skip to content

Commit 543b5df

Browse files
MDevereaullvmbot
authored andcommitted
[AArch64][SME] Implement inline-asm clobbers for za/zt0 (#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 (cherry picked from commit d9c20e4)
1 parent 0d656f0 commit 543b5df

File tree

5 files changed

+44
-1
lines changed

5 files changed

+44
-1
lines changed

clang/lib/Basic/Targets/AArch64.cpp

+8-1
Original file line numberDiff line numberDiff line change
@@ -1187,6 +1187,8 @@ TargetInfo::BuiltinVaListKind AArch64TargetInfo::getBuiltinVaListKind() const {
11871187
}
11881188

11891189
const char *const AArch64TargetInfo::GCCRegNames[] = {
1190+
// clang-format off
1191+
11901192
// 32-bit Integer registers
11911193
"w0", "w1", "w2", "w3", "w4", "w5", "w6", "w7", "w8", "w9", "w10", "w11",
11921194
"w12", "w13", "w14", "w15", "w16", "w17", "w18", "w19", "w20", "w21", "w22",
@@ -1223,7 +1225,12 @@ const char *const AArch64TargetInfo::GCCRegNames[] = {
12231225

12241226
// SVE predicate-as-counter registers
12251227
"pn0", "pn1", "pn2", "pn3", "pn4", "pn5", "pn6", "pn7", "pn8",
1226-
"pn9", "pn10", "pn11", "pn12", "pn13", "pn14", "pn15"
1228+
"pn9", "pn10", "pn11", "pn12", "pn13", "pn14", "pn15",
1229+
1230+
// SME registers
1231+
"za", "zt0",
1232+
1233+
// clang-format on
12271234
};
12281235

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

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

+8
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

+8
Original file line numberDiff line numberDiff line change
@@ -10718,6 +10718,14 @@ AArch64TargetLowering::getRegForInlineAsmConstraint(
1071810718
parseConstraintCode(Constraint) != AArch64CC::Invalid)
1071910719
return std::make_pair(unsigned(AArch64::NZCV), &AArch64::CCRRegClass);
1072010720

10721+
if (Constraint == "{za}") {
10722+
return std::make_pair(unsigned(AArch64::ZA), &AArch64::MPRRegClass);
10723+
}
10724+
10725+
if (Constraint == "{zt0}") {
10726+
return std::make_pair(unsigned(AArch64::ZT0), &AArch64::ZTRRegClass);
10727+
}
10728+
1072110729
// Use the default implementation in TargetLowering to convert the register
1072210730
// constraint into a member of a register class.
1072310731
std::pair<unsigned, const TargetRegisterClass *> Res;

llvm/lib/Target/AArch64/AArch64RegisterInfo.cpp

+4
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

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)