Skip to content

Commit a54b514

Browse files
authored
Merge branch 'main' into main
2 parents eb8799e + dfdc69b commit a54b514

14 files changed

+1452
-9
lines changed

llvm/lib/Target/Hexagon/HexagonBitSimplify.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1796,7 +1796,7 @@ namespace {
17961796

17971797
const MachineDominatorTree &MDT;
17981798
const HexagonInstrInfo &HII;
1799-
const HexagonRegisterInfo &HRI;
1799+
[[maybe_unused]] const HexagonRegisterInfo &HRI;
18001800
MachineRegisterInfo &MRI;
18011801
BitTracker &BT;
18021802
};

llvm/lib/Target/RISCV/MCTargetDesc/RISCVMatInt.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,32 @@ static void generateInstSeqImpl(int64_t Val, const MCSubtargetInfo &STI,
7979
}
8080
}
8181

82+
if (STI.hasFeature(RISCV::FeatureStdExtP)) {
83+
// Check if the immediate is packed i8 or i10
84+
int32_t Bit63To32 = Val >> 32;
85+
int32_t Bit31To0 = Val;
86+
int16_t Bit31To16 = Bit31To0 >> 16;
87+
int16_t Bit15To0 = Bit31To0;
88+
int8_t Bit15To8 = Bit15To0 >> 8;
89+
int8_t Bit7To0 = Bit15To0;
90+
if (Bit63To32 == Bit31To0) {
91+
if (IsRV64 && isInt<10>(Bit63To32)) {
92+
Res.emplace_back(RISCV::PLI_W, Bit63To32);
93+
return;
94+
}
95+
if (Bit31To16 == Bit15To0) {
96+
if (isInt<10>(Bit31To16)) {
97+
Res.emplace_back(RISCV::PLI_H, Bit31To16);
98+
return;
99+
}
100+
if (Bit15To8 == Bit7To0) {
101+
Res.emplace_back(RISCV::PLI_B, Bit15To8);
102+
return;
103+
}
104+
}
105+
}
106+
}
107+
82108
if (isInt<32>(Val)) {
83109
// Depending on the active bits in the immediate Value v, the following
84110
// instruction sequences are emitted:
@@ -562,6 +588,9 @@ OpndKind Inst::getOpndKind() const {
562588
case RISCV::LUI:
563589
case RISCV::QC_LI:
564590
case RISCV::QC_E_LI:
591+
case RISCV::PLI_B:
592+
case RISCV::PLI_H:
593+
case RISCV::PLI_W:
565594
return RISCVMatInt::Imm;
566595
case RISCV::ADD_UW:
567596
return RISCVMatInt::RegX0;

llvm/lib/Target/RISCV/MCTargetDesc/RISCVMatInt.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ namespace RISCVMatInt {
2121

2222
enum OpndKind {
2323
RegImm, // ADDI/ADDIW/XORI/SLLI/SRLI/SLLI_UW/RORI/BSETI/BCLRI/TH_SRRI
24-
Imm, // LUI/QC_LI/QC_E_LI
24+
Imm, // LUI/QC_LI/QC_E_LI/PLI_B/PLI_H/PLI_W
2525
RegReg, // SH1ADD/SH2ADD/SH3ADD/PACK
2626
RegX0, // ADD_UW
2727
};

llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -991,6 +991,18 @@ static unsigned getSegInstNF(unsigned Intrinsic) {
991991
}
992992
}
993993

994+
static bool isApplicableToPLI(int Val) {
995+
// Check if the immediate is packed i8 or i10
996+
int16_t Bit31To16 = Val >> 16;
997+
int16_t Bit15To0 = Val;
998+
int8_t Bit15To8 = Bit15To0 >> 8;
999+
int8_t Bit7To0 = Val;
1000+
if (Bit31To16 != Bit15To0)
1001+
return false;
1002+
1003+
return isInt<10>(Bit31To16) || Bit15To8 == Bit7To0;
1004+
}
1005+
9941006
void RISCVDAGToDAGISel::Select(SDNode *Node) {
9951007
// If we have a custom node, we have already selected.
9961008
if (Node->isMachineOpcode()) {
@@ -1034,6 +1046,14 @@ void RISCVDAGToDAGISel::Select(SDNode *Node) {
10341046
if (!isInt<32>(Imm) && isUInt<32>(Imm) && hasAllWUsers(Node))
10351047
Imm = SignExtend64<32>(Imm);
10361048

1049+
if (Subtarget->enablePExtCodeGen() && isApplicableToPLI(Imm) &&
1050+
hasAllWUsers(Node)) {
1051+
// If it's 4 packed 8-bit integers or 2 packed signed 16-bit integers, we
1052+
// can simply copy lower 32 bits to higher 32 bits to make it able to
1053+
// rematerialize to PLI_B or PLI_H
1054+
Imm = ((uint64_t)Imm << 32) | (Imm & 0xFFFFFFFF);
1055+
}
1056+
10371057
ReplaceNode(Node, selectImm(CurDAG, DL, VT, Imm, *Subtarget).getNode());
10381058
return;
10391059
}
@@ -2654,6 +2674,21 @@ void RISCVDAGToDAGISel::Select(SDNode *Node) {
26542674
CurDAG->RemoveDeadNode(Node);
26552675
return;
26562676
}
2677+
if (Subtarget->enablePExtCodeGen()) {
2678+
bool Is32BitCast =
2679+
(VT == MVT::i32 && (SrcVT == MVT::v4i8 || SrcVT == MVT::v2i16)) ||
2680+
(SrcVT == MVT::i32 && (VT == MVT::v4i8 || VT == MVT::v2i16));
2681+
bool Is64BitCast =
2682+
(VT == MVT::i64 && (SrcVT == MVT::v8i8 || SrcVT == MVT::v4i16 ||
2683+
SrcVT == MVT::v2i32)) ||
2684+
(SrcVT == MVT::i64 &&
2685+
(VT == MVT::v8i8 || VT == MVT::v4i16 || VT == MVT::v2i32));
2686+
if (Is32BitCast || Is64BitCast) {
2687+
ReplaceUses(SDValue(Node, 0), Node->getOperand(0));
2688+
CurDAG->RemoveDeadNode(Node);
2689+
return;
2690+
}
2691+
}
26572692
break;
26582693
}
26592694
case ISD::INSERT_SUBVECTOR:

0 commit comments

Comments
 (0)