Skip to content

Commit b62ea14

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. No functional change. While at it, restore vertical alignment for the definition lines. Suggested-by: tangaac <[email protected]> Link: #114398 (comment)
1 parent df9769e commit b62ea14

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1562,7 +1562,8 @@ 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::AMADD_D && Opc <= LoongArch::AMXOR_W &&
1566+
!(Opc >= LoongArch::AMCAS_B && Opc <= LoongArch::AMCAS__DB_W)) {
15661567
MCRegister Rd = Inst.getOperand(0).getReg();
15671568
MCRegister Rk = Inst.getOperand(1).getReg();
15681569
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)