Skip to content

Commit f0d7771

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 3f9d02a commit f0d7771

File tree

2 files changed

+23
-11
lines changed

2 files changed

+23
-11
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: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -710,11 +710,17 @@ class STORE_2RI14<bits<32> op>
710710
"$rd, $rj, $imm14">;
711711
} // hasSideEffects = 0, mayLoad = 0, mayStore = 1
712712

713-
let hasSideEffects = 0, mayLoad = 1, mayStore = 1, Constraints = "@earlyclobber $rd" in
714-
class AM_3R<bits<32> op>
713+
let hasSideEffects = 0, mayLoad = 1, mayStore = 1,
714+
Constraints = "@earlyclobber $rd" in 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,
719+
Constraints =
720+
"@earlyclobber $rd_wb, $rd_wb = $rd" in class AMCAS_3R<bits<32> op>
721+
: Fmt3R<op, (outs GPR:$rd_wb), (ins GPR:$rd, GPR:$rk, GPRMemAtomic:$rj),
722+
"$rd, $rk, $rj">;
723+
718724
let hasSideEffects = 0, mayLoad = 1, mayStore = 0 in {
719725
class LLBase<bits<32> op>
720726
: Fmt2RI14<op, (outs GPR:$rd), (ins GPR:$rj, simm14_lsl2:$imm14),
@@ -1024,14 +1030,14 @@ def AMMAX__DB_WU : AM_3R<0x38700000>;
10241030
def AMMAX__DB_DU : AM_3R<0x38708000>;
10251031
def AMMIN__DB_WU : AM_3R<0x38710000>;
10261032
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>;
1033+
def AMCAS_B : AMCAS_3R<0x38580000>;
1034+
def AMCAS_H : AMCAS_3R<0x38588000>;
1035+
def AMCAS_W : AMCAS_3R<0x38590000>;
1036+
def AMCAS_D : AMCAS_3R<0x38598000>;
1037+
def AMCAS__DB_B : AMCAS_3R<0x385a0000>;
1038+
def AMCAS__DB_H : AMCAS_3R<0x385a8000>;
1039+
def AMCAS__DB_W : AMCAS_3R<0x385b0000>;
1040+
def AMCAS__DB_D : AMCAS_3R<0x385b8000>;
10351041
def LL_D : LLBase<0x22000000>;
10361042
def SC_D : SCBase<0x23000000>;
10371043
def SC_Q : SCBase_128<0x38570000>;

0 commit comments

Comments
 (0)