[llvm] [RISCV] Support emitting plui.h for i32 constants on RV64. (PR #192534)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 16 14:04:48 PDT 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-backend-risc-v
Author: Craig Topper (topperc)
<details>
<summary>Changes</summary>
If the constant was originally i32, it will be sign or zero
extended to i64 during type legalization. If we can prove the
upper bits aren't used we can duplicate the lower bits to allow
RISCVMatInt to select plui.h.
---
Full diff: https://github.com/llvm/llvm-project/pull/192534.diff
1 Files Affected:
- (modified) llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp (+5-3)
``````````diff
diff --git a/llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp b/llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp
index e428769818727..359ba913589a6 100644
--- a/llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp
+++ b/llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp
@@ -1082,7 +1082,7 @@ static unsigned getSegInstNF(unsigned Intrinsic) {
}
}
-static bool isApplicableToPLI(int Val) {
+static bool isApplicableToPLIOrPLUI(int Val) {
// Check if the immediate is packed i8 or i10
int16_t Bit31To16 = Val >> 16;
int16_t Bit15To0 = Val;
@@ -1091,7 +1091,8 @@ static bool isApplicableToPLI(int Val) {
if (Bit31To16 != Bit15To0)
return false;
- return isInt<10>(Bit31To16) || Bit15To8 == Bit7To0;
+ return isInt<10>(Bit15To0) || isShiftedInt<10, 6>(Bit15To0) ||
+ Bit15To8 == Bit7To0;
}
void RISCVDAGToDAGISel::Select(SDNode *Node) {
@@ -1151,7 +1152,8 @@ void RISCVDAGToDAGISel::Select(SDNode *Node) {
if (!isInt<32>(Imm) && isUInt<32>(Imm) && hasAllWUsers(Node))
Imm = SignExtend64<32>(Imm);
- if (VT == MVT::i64 && Subtarget->hasStdExtP() && isApplicableToPLI(Imm) &&
+ if (VT == MVT::i64 && !isInt<12>(Imm) && !isShiftedInt<20, 12>(Imm) &&
+ Subtarget->hasStdExtP() && isApplicableToPLIOrPLUI(Imm) &&
hasAllWUsers(Node)) {
// 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
``````````
</details>
https://github.com/llvm/llvm-project/pull/192534
More information about the llvm-commits
mailing list