Skip to content

Commit 830b8f5

Browse files
committed
[LoongArch][NFC] Fix the operand constraint of AMCAS instructions
The `rd` operand of AMCAS instructions is both read and written, because of the nature of compare-and-swap operations, but currently it is not declared as such. Fix it for upcoming codegen enablement changes. In order to do that, a piece of LoongArchAsmParser logic that relied on TableGen-erated enum variants being ordered in a specific way needs updating; this will be addressed in a following refactor. No functional change intended. While at it, restore vertical alignment for the definition lines. Suggested-by: tangaac <[email protected]> Link: #114398 (comment)
1 parent 7085ac8 commit 830b8f5

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

llvm/lib/Target/LoongArch/AsmParser/LoongArchAsmParser.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1562,7 +1562,13 @@ unsigned LoongArchAsmParser::checkTargetMatchPredicate(MCInst &Inst) {
15621562
unsigned Opc = Inst.getOpcode();
15631563
switch (Opc) {
15641564
default:
1565-
if (Opc >= LoongArch::AMADD_D && Opc <= LoongArch::AMXOR_W) {
1565+
if (Opc >= LoongArch::AMCAS_B && Opc <= LoongArch::AMCAS__DB_W) {
1566+
MCRegister Rd = Inst.getOperand(0).getReg();
1567+
MCRegister Rk = Inst.getOperand(2).getReg();
1568+
MCRegister Rj = Inst.getOperand(3).getReg();
1569+
if ((Rd == Rk || Rd == Rj) && Rd != LoongArch::R0)
1570+
return Match_RequiresAMORdDifferRkRj;
1571+
} else if (Opc >= LoongArch::AMADD_D && Opc <= LoongArch::AMXOR_W) {
15661572
MCRegister Rd = Inst.getOperand(0).getReg();
15671573
MCRegister Rk = Inst.getOperand(1).getReg();
15681574
MCRegister Rj = Inst.getOperand(2).getReg();

llvm/lib/Target/LoongArch/LoongArchInstrInfo.td

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -715,6 +715,11 @@ class AM_3R<bits<32> op>
715715
: Fmt3R<op, (outs GPR:$rd), (ins GPR:$rk, GPRMemAtomic:$rj),
716716
"$rd, $rk, $rj">;
717717

718+
let hasSideEffects = 0, mayLoad = 1, mayStore = 1, Constraints = "$rd = $rd_wb" in
719+
class AMCAS_3R<bits<32> op>
720+
: Fmt3R<op, (outs GPR:$rd_wb), (ins GPR:$rd, GPR:$rk, GPRMemAtomic:$rj),
721+
"$rd, $rk, $rj">;
722+
718723
let hasSideEffects = 0, mayLoad = 1, mayStore = 0 in {
719724
class LLBase<bits<32> op>
720725
: Fmt2RI14<op, (outs GPR:$rd), (ins GPR:$rj, simm14_lsl2:$imm14),
@@ -1024,14 +1029,14 @@ def AMMAX__DB_WU : AM_3R<0x38700000>;
10241029
def AMMAX__DB_DU : AM_3R<0x38708000>;
10251030
def AMMIN__DB_WU : AM_3R<0x38710000>;
10261031
def AMMIN__DB_DU : AM_3R<0x38718000>;
1027-
def AMCAS_B : AM_3R<0x38580000>;
1028-
def AMCAS_H : AM_3R<0x38588000>;
1029-
def AMCAS_W : AM_3R<0x38590000>;
1030-
def AMCAS_D : AM_3R<0x38598000>;
1031-
def AMCAS__DB_B : AM_3R<0x385a0000>;
1032-
def AMCAS__DB_H : AM_3R<0x385a8000>;
1033-
def AMCAS__DB_W : AM_3R<0x385b0000>;
1034-
def AMCAS__DB_D : AM_3R<0x385b8000>;
1032+
def AMCAS_B : AMCAS_3R<0x38580000>;
1033+
def AMCAS_H : AMCAS_3R<0x38588000>;
1034+
def AMCAS_W : AMCAS_3R<0x38590000>;
1035+
def AMCAS_D : AMCAS_3R<0x38598000>;
1036+
def AMCAS__DB_B : AMCAS_3R<0x385a0000>;
1037+
def AMCAS__DB_H : AMCAS_3R<0x385a8000>;
1038+
def AMCAS__DB_W : AMCAS_3R<0x385b0000>;
1039+
def AMCAS__DB_D : AMCAS_3R<0x385b8000>;
10351040
def LL_D : LLBase<0x22000000>;
10361041
def SC_D : SCBase<0x23000000>;
10371042
def SC_Q : SCBase_128<0x38570000>;

0 commit comments

Comments
 (0)