Skip to content

Commit e20d353

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 e20d353

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1568,6 +1568,12 @@ unsigned LoongArchAsmParser::checkTargetMatchPredicate(MCInst &Inst) {
15681568
MCRegister Rj = Inst.getOperand(2).getReg();
15691569
if ((Rd == Rk || Rd == Rj) && Rd != LoongArch::R0)
15701570
return Match_RequiresAMORdDifferRkRj;
1571+
} else if (Opc >= LoongArch::AMCAS_B && Opc <= LoongArch::AMCAS__DB_W) {
1572+
MCRegister Rd = Inst.getOperand(0).getReg();
1573+
MCRegister Rk = Inst.getOperand(2).getReg();
1574+
MCRegister Rj = Inst.getOperand(3).getReg();
1575+
if ((Rd == Rk || Rd == Rj) && Rd != LoongArch::R0)
1576+
return Match_RequiresAMORdDifferRkRj;
15711577
}
15721578
break;
15731579
case LoongArch::PseudoLA_TLS_DESC:

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)