Skip to content

Commit 746c682

Browse files
authored
[LoongArch] Introduce 32s target feature for LA32S ISA extensions (llvm#139695)
According to the offical LoongArch reference manual, the 32-bit LoongArch is divied into two variants: the Reduced version (LA32R) and Standard version (LA32S). LA32S extends LA32R by adding additional instructions, and the 64-bit version (LA64) fully includes the LA32S instruction set. This patch introduces a new target feature `32s` for the LoongArch backend, enabling support for instructions specific to the LA32S variant. The LA32S exntension includes the following additional instructions: - ALSL.W - {AND,OR}N - B{EQ,NE}Z - BITREV.{4B,W} - BSTR{INS,PICK}.W - BYTEPICK.W - CL{O,Z}.W - CPUCFG - CT{O,Z}.W - EXT.W,{B,H} - F{LD,ST}X.{D,S} - MASK{EQ,NE}Z - PC{ADDI,ALAU12I} - REVB.2H - ROTR{I},W Additionally, LA32R defines three new instruction aliases: - RDCNTID.W RJ => RDTIMEL.W ZERO, RJ - RDCNTVH.W RD => RDTIMEH.W RD, ZERO - RDCNTVL.W RD => RDTIMEL.W RD, ZERO
1 parent a630309 commit 746c682

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+14418
-6696
lines changed

llvm/lib/Target/LoongArch/LoongArch.td

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,18 @@ include "llvm/Target/Target.td"
1414

1515
// LoongArch is divided into two versions, the 32-bit version (LA32) and the
1616
// 64-bit version (LA64).
17+
18+
// LoongArch 32-bit is divided into two variants, the reduced 32-bit variant
19+
// (LA32R) and the standard 32-bit variant (LA32S).
20+
def Feature32S
21+
: SubtargetFeature<"32s", "Has32S", "true",
22+
"LA32 Standard Basic Instruction Extension">;
23+
def Has32S : Predicate<"Subtarget->has32S()">;
24+
1725
def Feature64Bit
1826
: SubtargetFeature<"64bit", "HasLA64", "true",
19-
"LA64 Basic Integer and Privilege Instruction Set">;
27+
"LA64 Basic Integer and Privilege Instruction Set",
28+
[Feature32S]>;
2029
def Feature32Bit
2130
: SubtargetFeature<"32bit", "HasLA32", "true",
2231
"LA32 Basic Integer and Privilege Instruction Set">;

llvm/lib/Target/LoongArch/LoongArchExpandAtomicPseudoInsts.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,9 @@ static void doAtomicBinOpExpansion(const LoongArchInstrInfo *TII,
214214
.addReg(ScratchReg)
215215
.addReg(AddrReg)
216216
.addImm(0);
217-
BuildMI(LoopMBB, DL, TII->get(LoongArch::BEQZ))
217+
BuildMI(LoopMBB, DL, TII->get(LoongArch::BEQ))
218218
.addReg(ScratchReg)
219+
.addReg(LoongArch::R0)
219220
.addMBB(LoopMBB);
220221
}
221222

@@ -296,8 +297,9 @@ static void doMaskedAtomicBinOpExpansion(
296297
.addReg(ScratchReg)
297298
.addReg(AddrReg)
298299
.addImm(0);
299-
BuildMI(LoopMBB, DL, TII->get(LoongArch::BEQZ))
300+
BuildMI(LoopMBB, DL, TII->get(LoongArch::BEQ))
300301
.addReg(ScratchReg)
302+
.addReg(LoongArch::R0)
301303
.addMBB(LoopMBB);
302304
}
303305

@@ -454,8 +456,9 @@ bool LoongArchExpandAtomicPseudo::expandAtomicMinMaxOp(
454456
.addReg(Scratch1Reg)
455457
.addReg(AddrReg)
456458
.addImm(0);
457-
BuildMI(LoopTailMBB, DL, TII->get(LoongArch::BEQZ))
459+
BuildMI(LoopTailMBB, DL, TII->get(LoongArch::BEQ))
458460
.addReg(Scratch1Reg)
461+
.addReg(LoongArch::R0)
459462
.addMBB(LoopHeadMBB);
460463

461464
NextMBBI = MBB.end();
@@ -529,8 +532,9 @@ bool LoongArchExpandAtomicPseudo::expandAtomicCmpXchg(
529532
.addReg(ScratchReg)
530533
.addReg(AddrReg)
531534
.addImm(0);
532-
BuildMI(LoopTailMBB, DL, TII->get(LoongArch::BEQZ))
535+
BuildMI(LoopTailMBB, DL, TII->get(LoongArch::BEQ))
533536
.addReg(ScratchReg)
537+
.addReg(LoongArch::R0)
534538
.addMBB(LoopHeadMBB);
535539
BuildMI(LoopTailMBB, DL, TII->get(LoongArch::B)).addMBB(DoneMBB);
536540
} else {
@@ -569,8 +573,9 @@ bool LoongArchExpandAtomicPseudo::expandAtomicCmpXchg(
569573
.addReg(ScratchReg)
570574
.addReg(AddrReg)
571575
.addImm(0);
572-
BuildMI(LoopTailMBB, DL, TII->get(LoongArch::BEQZ))
576+
BuildMI(LoopTailMBB, DL, TII->get(LoongArch::BEQ))
573577
.addReg(ScratchReg)
578+
.addReg(LoongArch::R0)
574579
.addMBB(LoopHeadMBB);
575580
BuildMI(LoopTailMBB, DL, TII->get(LoongArch::B)).addMBB(DoneMBB);
576581
}
@@ -677,8 +682,9 @@ bool LoongArchExpandAtomicPseudo::expandAtomicCmpXchg128(
677682
.addReg(ScratchReg)
678683
.addReg(NewValHiReg)
679684
.addReg(AddrReg);
680-
BuildMI(LoopTailMBB, DL, TII->get(LoongArch::BEQZ))
685+
BuildMI(LoopTailMBB, DL, TII->get(LoongArch::BEQ))
681686
.addReg(ScratchReg)
687+
.addReg(LoongArch::R0)
682688
.addMBB(LoopHeadMBB);
683689
BuildMI(LoopTailMBB, DL, TII->get(LoongArch::B)).addMBB(DoneMBB);
684690
int hint;

llvm/lib/Target/LoongArch/LoongArchISelDAGToDAG.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,28 @@ class LoongArchDAGToDAGISel : public SelectionDAGISel {
6464
bool selectVSplatUimmInvPow2(SDValue N, SDValue &SplatImm) const;
6565
bool selectVSplatUimmPow2(SDValue N, SDValue &SplatImm) const;
6666

67+
// Return the LoongArch branch opcode that matches the given DAG integer
68+
// condition code. The CondCode must be one of those supported by the
69+
// LoongArch ISA (see translateSetCCForBranch).
70+
static unsigned getBranchOpcForIntCC(ISD::CondCode CC) {
71+
switch (CC) {
72+
default:
73+
llvm_unreachable("Unsupported CondCode");
74+
case ISD::SETEQ:
75+
return LoongArch::BEQ;
76+
case ISD::SETNE:
77+
return LoongArch::BNE;
78+
case ISD::SETLT:
79+
return LoongArch::BLT;
80+
case ISD::SETGE:
81+
return LoongArch::BGE;
82+
case ISD::SETULT:
83+
return LoongArch::BLTU;
84+
case ISD::SETUGE:
85+
return LoongArch::BGEU;
86+
}
87+
}
88+
6789
// Include the pieces autogenerated from the target description.
6890
#include "LoongArchGenDAGISel.inc"
6991
};

0 commit comments

Comments
 (0)