Skip to content

Commit 42b193c

Browse files
authored
[AMX] Error out when AMX DP instructions use same registers (llvm#97686)
Fixes llvm#97522
1 parent 7fb71d1 commit 42b193c

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3849,6 +3849,14 @@ bool X86AsmParser::validateInstruction(MCInst &Inst, const OperandVector &Ops) {
38493849
return Warning(Ops[0]->getStartLoc(), "mask, index, and destination "
38503850
"registers should be distinct");
38513851
}
3852+
} else if (isTCMMIMFP16PS(Opcode) || isTCMMRLFP16PS(Opcode) ||
3853+
isTDPBF16PS(Opcode) || isTDPFP16PS(Opcode) || isTDPBSSD(Opcode) ||
3854+
isTDPBSUD(Opcode) || isTDPBUSD(Opcode) || isTDPBUUD(Opcode)) {
3855+
unsigned SrcDest = Inst.getOperand(0).getReg();
3856+
unsigned Src1 = Inst.getOperand(2).getReg();
3857+
unsigned Src2 = Inst.getOperand(3).getReg();
3858+
if (SrcDest == Src1 || SrcDest == Src2 || Src1 == Src2)
3859+
return Error(Ops[0]->getStartLoc(), "all tmm registers must be distinct");
38523860
}
38533861

38543862
// Check that we aren't mixing AH/BH/CH/DH with REX prefix. We only need to

llvm/test/MC/X86/AMX/amx-error.s

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// RUN: not llvm-mc -triple x86_64 %s 2>&1 | FileCheck %s
2+
3+
// CHECK: error: all tmm registers must be distinct
4+
tcmmimfp16ps %tmm0, %tmm0, %tmm0
5+
6+
// CHECK: error: all tmm registers must be distinct
7+
tcmmrlfp16ps %tmm1, %tmm0, %tmm1
8+
9+
// CHECK: error: all tmm registers must be distinct
10+
tdpbf16ps %tmm2, %tmm2, %tmm0
11+
12+
// CHECK: error: all tmm registers must be distinct
13+
tdpfp16ps %tmm3, %tmm0, %tmm0
14+
15+
// CHECK: error: all tmm registers must be distinct
16+
tdpbssd %tmm0, %tmm0, %tmm0
17+
18+
// CHECK: error: all tmm registers must be distinct
19+
tdpbsud %tmm1, %tmm0, %tmm1
20+
21+
// CHECK: error: all tmm registers must be distinct
22+
tdpbusd %tmm2, %tmm2, %tmm0
23+
24+
// CHECK: error: all tmm registers must be distinct
25+
tdpbuud %tmm3, %tmm0, %tmm0

0 commit comments

Comments
 (0)