Skip to content

Commit 3ce7e72

Browse files
committed
[LoongArch] Introduce 32s target feature for LA32S ISA extensions
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 e618a79 commit 3ce7e72

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

+14426
-6696
lines changed

llvm/lib/Target/LoongArch/LoongArch.td

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@ def IsLA32
3232
defvar LA32 = DefaultMode;
3333
def LA64 : HwMode<"+64bit", [IsLA64]>;
3434

35+
// LoongArch 32-bit is divided into two variants, the reduced 32-bit variant
36+
// (LA32R) and the standard 32-bit variant (LA32S).
37+
def Feature32S
38+
: SubtargetFeature<"32s", "Has32S", "true",
39+
"LA32 Standard Basic Instruction Extension">;
40+
def Has32S : Predicate<"Subtarget->has32S()">;
41+
def Not32S : Predicate<"!Subtarget->has32S()">;
42+
3543
// Single Precision floating point
3644
def FeatureBasicF
3745
: SubtargetFeature<"f", "HasBasicF", "true",
@@ -159,11 +167,13 @@ include "LoongArchInstrInfo.td"
159167

160168
def : ProcessorModel<"generic-la32", NoSchedModel, [Feature32Bit]>;
161169
def : ProcessorModel<"generic-la64", NoSchedModel, [Feature64Bit,
170+
Feature32S,
162171
FeatureUAL,
163172
FeatureExtLSX]>;
164173

165174
// Generic 64-bit processor with double-precision floating-point support.
166175
def : ProcessorModel<"loongarch64", NoSchedModel, [Feature64Bit,
176+
Feature32S,
167177
FeatureUAL,
168178
FeatureBasicD]>;
169179

@@ -172,12 +182,14 @@ def : ProcessorModel<"loongarch64", NoSchedModel, [Feature64Bit,
172182
def : ProcessorModel<"generic", NoSchedModel, []>;
173183

174184
def : ProcessorModel<"la464", NoSchedModel, [Feature64Bit,
185+
Feature32S,
175186
FeatureUAL,
176187
FeatureExtLASX,
177188
FeatureExtLVZ,
178189
FeatureExtLBT]>;
179190

180191
def : ProcessorModel<"la664", NoSchedModel, [Feature64Bit,
192+
Feature32S,
181193
FeatureUAL,
182194
FeatureExtLASX,
183195
FeatureExtLVZ,

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)