Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion llvm/lib/Target/LoongArch/LoongArch.td
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,18 @@ include "llvm/Target/Target.td"

// LoongArch is divided into two versions, the 32-bit version (LA32) and the
// 64-bit version (LA64).

// LoongArch 32-bit is divided into two variants, the reduced 32-bit variant
// (LA32R) and the standard 32-bit variant (LA32S).
def Feature32S
: SubtargetFeature<"32s", "Has32S", "true",
"LA32 Standard Basic Instruction Extension">;
def Has32S : Predicate<"Subtarget->has32S()">;

def Feature64Bit
: SubtargetFeature<"64bit", "HasLA64", "true",
"LA64 Basic Integer and Privilege Instruction Set">;
"LA64 Basic Integer and Privilege Instruction Set",
[Feature32S]>;
def Feature32Bit
: SubtargetFeature<"32bit", "HasLA32", "true",
"LA32 Basic Integer and Privilege Instruction Set">;
Expand Down
18 changes: 12 additions & 6 deletions llvm/lib/Target/LoongArch/LoongArchExpandAtomicPseudoInsts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,9 @@ static void doAtomicBinOpExpansion(const LoongArchInstrInfo *TII,
.addReg(ScratchReg)
.addReg(AddrReg)
.addImm(0);
BuildMI(LoopMBB, DL, TII->get(LoongArch::BEQZ))
BuildMI(LoopMBB, DL, TII->get(LoongArch::BEQ))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BEQZ has the advantage over BEQ in that its reach is broader by 5 bits (width of a GPR slot), so if some of the changed bits potentially refers to a remote MBB, we may want to preserve them? I'm not looking at this code as closely as I'd prefer because I'm just battling my procrastination and doing a quick review here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. While BEQZ does offer a wider branch range than BEQ, their latency and throughput are the same. For expanding the pseudo-atomic seqences, I believe BEQ's range is sufficient. I chose not to split it further to avoid unnecessary divergence between the 32-bit and 64-bit code paths.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is acceptable to me.

.addReg(ScratchReg)
.addReg(LoongArch::R0)
.addMBB(LoopMBB);
}

Expand Down Expand Up @@ -296,8 +297,9 @@ static void doMaskedAtomicBinOpExpansion(
.addReg(ScratchReg)
.addReg(AddrReg)
.addImm(0);
BuildMI(LoopMBB, DL, TII->get(LoongArch::BEQZ))
BuildMI(LoopMBB, DL, TII->get(LoongArch::BEQ))
.addReg(ScratchReg)
.addReg(LoongArch::R0)
.addMBB(LoopMBB);
}

Expand Down Expand Up @@ -454,8 +456,9 @@ bool LoongArchExpandAtomicPseudo::expandAtomicMinMaxOp(
.addReg(Scratch1Reg)
.addReg(AddrReg)
.addImm(0);
BuildMI(LoopTailMBB, DL, TII->get(LoongArch::BEQZ))
BuildMI(LoopTailMBB, DL, TII->get(LoongArch::BEQ))
.addReg(Scratch1Reg)
.addReg(LoongArch::R0)
.addMBB(LoopHeadMBB);

NextMBBI = MBB.end();
Expand Down Expand Up @@ -529,8 +532,9 @@ bool LoongArchExpandAtomicPseudo::expandAtomicCmpXchg(
.addReg(ScratchReg)
.addReg(AddrReg)
.addImm(0);
BuildMI(LoopTailMBB, DL, TII->get(LoongArch::BEQZ))
BuildMI(LoopTailMBB, DL, TII->get(LoongArch::BEQ))
.addReg(ScratchReg)
.addReg(LoongArch::R0)
.addMBB(LoopHeadMBB);
BuildMI(LoopTailMBB, DL, TII->get(LoongArch::B)).addMBB(DoneMBB);
} else {
Expand Down Expand Up @@ -569,8 +573,9 @@ bool LoongArchExpandAtomicPseudo::expandAtomicCmpXchg(
.addReg(ScratchReg)
.addReg(AddrReg)
.addImm(0);
BuildMI(LoopTailMBB, DL, TII->get(LoongArch::BEQZ))
BuildMI(LoopTailMBB, DL, TII->get(LoongArch::BEQ))
.addReg(ScratchReg)
.addReg(LoongArch::R0)
.addMBB(LoopHeadMBB);
BuildMI(LoopTailMBB, DL, TII->get(LoongArch::B)).addMBB(DoneMBB);
}
Expand Down Expand Up @@ -677,8 +682,9 @@ bool LoongArchExpandAtomicPseudo::expandAtomicCmpXchg128(
.addReg(ScratchReg)
.addReg(NewValHiReg)
.addReg(AddrReg);
BuildMI(LoopTailMBB, DL, TII->get(LoongArch::BEQZ))
BuildMI(LoopTailMBB, DL, TII->get(LoongArch::BEQ))
.addReg(ScratchReg)
.addReg(LoongArch::R0)
.addMBB(LoopHeadMBB);
BuildMI(LoopTailMBB, DL, TII->get(LoongArch::B)).addMBB(DoneMBB);
int hint;
Expand Down
22 changes: 22 additions & 0 deletions llvm/lib/Target/LoongArch/LoongArchISelDAGToDAG.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,28 @@ class LoongArchDAGToDAGISel : public SelectionDAGISel {
bool selectVSplatUimmInvPow2(SDValue N, SDValue &SplatImm) const;
bool selectVSplatUimmPow2(SDValue N, SDValue &SplatImm) const;

// Return the LoongArch branch opcode that matches the given DAG integer
// condition code. The CondCode must be one of those supported by the
// LoongArch ISA (see translateSetCCForBranch).
static unsigned getBranchOpcForIntCC(ISD::CondCode CC) {
switch (CC) {
default:
llvm_unreachable("Unsupported CondCode");
case ISD::SETEQ:
return LoongArch::BEQ;
case ISD::SETNE:
return LoongArch::BNE;
case ISD::SETLT:
return LoongArch::BLT;
case ISD::SETGE:
return LoongArch::BGE;
case ISD::SETULT:
return LoongArch::BLTU;
case ISD::SETUGE:
return LoongArch::BGEU;
}
}

// Include the pieces autogenerated from the target description.
#include "LoongArchGenDAGISel.inc"
};
Expand Down
Loading