[llvm] [MIPS]: Rework atomic max/min expand for subword (PR #89575)
YunQiang Su via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 23 00:31:56 PDT 2024
================
@@ -473,48 +476,38 @@ bool MipsExpandPseudo::expandAtomicBinOpSubword(
unsigned SELOldVal = IsMax ? SELEQZ : SELNEZ;
unsigned MOVIncr = IsMax ? MOVN : MOVZ;
- // For little endian we need to clear uninterested bits.
- if (STI->isLittle()) {
- if (!IsUnsigned) {
- BuildMI(loopMBB, DL, TII->get(Mips::SRAV), OldVal)
- .addReg(OldVal)
- .addReg(ShiftAmnt);
- BuildMI(loopMBB, DL, TII->get(Mips::SRAV), Incr)
- .addReg(Incr)
- .addReg(ShiftAmnt);
- if (STI->hasMips32r2()) {
- BuildMI(loopMBB, DL, TII->get(SEOp), OldVal).addReg(OldVal);
- BuildMI(loopMBB, DL, TII->get(SEOp), Incr).addReg(Incr);
- } else {
- const unsigned ShiftImm = SEOp == Mips::SEH ? 16 : 24;
- BuildMI(loopMBB, DL, TII->get(Mips::SLL), OldVal)
- .addReg(OldVal, RegState::Kill)
- .addImm(ShiftImm);
- BuildMI(loopMBB, DL, TII->get(Mips::SRA), OldVal)
- .addReg(OldVal, RegState::Kill)
- .addImm(ShiftImm);
- BuildMI(loopMBB, DL, TII->get(Mips::SLL), Incr)
- .addReg(Incr, RegState::Kill)
- .addImm(ShiftImm);
- BuildMI(loopMBB, DL, TII->get(Mips::SRA), Incr)
- .addReg(Incr, RegState::Kill)
- .addImm(ShiftImm);
- }
- } else {
- // and OldVal, OldVal, Mask
- // and Incr, Incr, Mask
- BuildMI(loopMBB, DL, TII->get(Mips::AND), OldVal)
- .addReg(OldVal)
- .addReg(Mask);
- BuildMI(loopMBB, DL, TII->get(Mips::AND), Incr)
- .addReg(Incr)
- .addReg(Mask);
- }
+ BuildMI(loopMBB, DL, TII->get(Mips::SRAV), StoreVal)
+ .addReg(OldVal)
+ .addReg(ShiftAmnt);
+ if (STI->hasMips32r2() && !IsUnsigned) {
+ BuildMI(loopMBB, DL, TII->get(SEOp), StoreVal).addReg(StoreVal);
+ } else if (STI->hasMips32r2() && IsUnsigned) {
+ const unsigned OpMask = SEOp == Mips::SEH ? 0xffff : 0xff;
+ BuildMI(loopMBB, DL, TII->get(Mips::ANDi), StoreVal)
+ .addReg(StoreVal)
+ .addImm(OpMask);
+ } else {
+ const unsigned ShiftImm = SEOp == Mips::SEH ? 16 : 24;
+ const unsigned SROp = IsUnsigned ? Mips::SRL : Mips::SRA;
+ BuildMI(loopMBB, DL, TII->get(Mips::SLL), StoreVal)
+ .addReg(StoreVal, RegState::Kill)
+ .addImm(ShiftImm);
+ BuildMI(loopMBB, DL, TII->get(SROp), StoreVal)
+ .addReg(StoreVal, RegState::Kill)
+ .addImm(ShiftImm);
----------------
wzssyqa wrote:
You are right. `ANDi` is available for all ISA revisions.
So we can
```
if (IsUnsigned)
ANDi
else if (STI->hasMips32r2())
SEH/SEB
else
SLL
SRA
```
Can you file a new PR for it?
https://github.com/llvm/llvm-project/pull/89575
More information about the llvm-commits
mailing list