Skip to content
Merged
Show file tree
Hide file tree
Changes from 17 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
29 changes: 29 additions & 0 deletions llvm/lib/Target/RISCV/MCTargetDesc/RISCVMatInt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,32 @@ static void generateInstSeqImpl(int64_t Val, const MCSubtargetInfo &STI,
}
}

if (STI.hasFeature(RISCV::FeatureStdExtP)) {
// Check if the immediate is packed i8 or i10
int32_t Bit63To32 = Val >> 32;
int32_t Bit31To0 = Val;
int16_t Bit31To16 = Bit31To0 >> 16;
int16_t Bit15To0 = Bit31To0;
int8_t Bit15To8 = Bit15To0 >> 8;
int8_t Bit7To0 = Bit15To0;
if (Bit63To32 == Bit31To0) {
if (IsRV64 && isInt<10>(Bit63To32)) {
Res.emplace_back(RISCV::PLI_W, Bit63To32);
return;
}
if (Bit31To16 == Bit15To0) {
if (isInt<10>(Bit31To16)) {
Res.emplace_back(RISCV::PLI_H, Bit31To16);
return;
}
if (Bit15To8 == Bit7To0) {
Res.emplace_back(RISCV::PLI_B, Bit15To8);
return;
}
}
}
}

if (isInt<32>(Val)) {
// Depending on the active bits in the immediate Value v, the following
// instruction sequences are emitted:
Expand Down Expand Up @@ -562,6 +588,9 @@ OpndKind Inst::getOpndKind() const {
case RISCV::LUI:
case RISCV::QC_LI:
case RISCV::QC_E_LI:
case RISCV::PLI_B:
case RISCV::PLI_H:
case RISCV::PLI_W:
return RISCVMatInt::Imm;
case RISCV::ADD_UW:
return RISCVMatInt::RegX0;
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Target/RISCV/MCTargetDesc/RISCVMatInt.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace RISCVMatInt {

enum OpndKind {
RegImm, // ADDI/ADDIW/XORI/SLLI/SRLI/SLLI_UW/RORI/BSETI/BCLRI/TH_SRRI
Imm, // LUI/QC_LI/QC_E_LI
Imm, // LUI/QC_LI/QC_E_LI/PLI_B/PLI_H/PLI_W
RegReg, // SH1ADD/SH2ADD/SH3ADD/PACK
RegX0, // ADD_UW
};
Expand Down
35 changes: 35 additions & 0 deletions llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -991,6 +991,18 @@ static unsigned getSegInstNF(unsigned Intrinsic) {
}
}

static bool isApplicableToPLI(int Val) {
// Check if the immediate is packed i8 or i10
int16_t Bit31To16 = Val >> 16;
int16_t Bit15To0 = Val;
int8_t Bit15To8 = Bit15To0 >> 8;
int8_t Bit7To0 = Val;
if (Bit31To16 != Bit15To0)
return false;

return isInt<10>(Bit31To16) || Bit15To8 == Bit7To0;
}

void RISCVDAGToDAGISel::Select(SDNode *Node) {
// If we have a custom node, we have already selected.
if (Node->isMachineOpcode()) {
Expand Down Expand Up @@ -1034,6 +1046,14 @@ void RISCVDAGToDAGISel::Select(SDNode *Node) {
if (!isInt<32>(Imm) && isUInt<32>(Imm) && hasAllWUsers(Node))
Imm = SignExtend64<32>(Imm);

if (Subtarget->enablePExtCodeGen() && isApplicableToPLI(Imm) &&
hasAllWUsers(Node)) {
// If its 4 packed 8-bit integers or 2 packed signed 16-bit integers, we
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
// If its 4 packed 8-bit integers or 2 packed signed 16-bit integers, we
// If it's 4 packed 8-bit integers or 2 packed signed 16-bit integers, we

// can simply copy lower 32 bits to higher 32 bits to make it able to
// rematerialize to PLI_B or PLI_H
Imm = ((uint64_t)Imm << 32) | (Imm & 0xFFFFFFFF);
}

ReplaceNode(Node, selectImm(CurDAG, DL, VT, Imm, *Subtarget).getNode());
return;
}
Expand Down Expand Up @@ -2654,6 +2674,21 @@ void RISCVDAGToDAGISel::Select(SDNode *Node) {
CurDAG->RemoveDeadNode(Node);
return;
}
if (Subtarget->enablePExtCodeGen()) {
bool Is32BitCast =
(VT == MVT::i32 && (SrcVT == MVT::v4i8 || SrcVT == MVT::v2i16)) ||
(SrcVT == MVT::i32 && (VT == MVT::v4i8 || VT == MVT::v2i16));
bool Is64BitCast =
(VT == MVT::i64 && (SrcVT == MVT::v8i8 || SrcVT == MVT::v4i16 ||
SrcVT == MVT::v2i32)) ||
(SrcVT == MVT::i64 &&
(VT == MVT::v8i8 || VT == MVT::v4i16 || VT == MVT::v2i32));
if (Is32BitCast || Is64BitCast) {
ReplaceUses(SDValue(Node, 0), Node->getOperand(0));
CurDAG->RemoveDeadNode(Node);
return;
}
}
break;
}
case ISD::INSERT_SUBVECTOR:
Expand Down
Loading