[llvm] [RISCV] Reduce code duplication. NFC (PR #171577)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Dec 10 00:12:57 PST 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-backend-risc-v
Author: Craig Topper (topperc)
<details>
<summary>Changes</summary>
This code only different in the opcodes of the nodes it created.
---
Full diff: https://github.com/llvm/llvm-project/pull/171577.diff
1 Files Affected:
- (modified) llvm/lib/Target/RISCV/RISCVISelLowering.cpp (+6-11)
``````````diff
diff --git a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
index f28772a74d433..29fc2ddb818b5 100644
--- a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
+++ b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
@@ -9786,22 +9786,17 @@ SDValue RISCVTargetLowering::lowerSELECT(SDValue Op, SelectionDAG &DAG) const {
SDValue ConstVal = IsCZERO_NEZ ? TrueV : FalseV;
SDValue RegV = IsCZERO_NEZ ? FalseV : TrueV;
int64_t RawConstVal = cast<ConstantSDNode>(ConstVal)->getSExtValue();
- // Fall back to XORI if Const == -0x800
- if (RawConstVal == -0x800) {
- SDValue XorOp = DAG.getNode(ISD::XOR, DL, VT, RegV, ConstVal);
- SDValue CMOV =
- DAG.getNode(IsCZERO_NEZ ? RISCVISD::CZERO_NEZ : RISCVISD::CZERO_EQZ,
- DL, VT, XorOp, CondV);
- return DAG.getNode(ISD::XOR, DL, VT, CMOV, ConstVal);
- }
// Efficient only if the constant and its negation fit into `ADDI`
// Prefer Add/Sub over Xor since can be compressed for small immediates
if (isInt<12>(RawConstVal)) {
- SDValue SubOp = DAG.getNode(ISD::SUB, DL, VT, RegV, ConstVal);
- SDValue CMOV =
+ // Fall back to XORI if Const == -0x800 since we don't have SUBI.
+ unsigned SubOpc = (RawConstVal == -0x800) ? ISD::XOR : ISD::SUB;
+ unsigned AddOpc = (RawConstVal == -0x800) ? ISD::XOR : ISD::ADD;
+ SDValue SubOp = DAG.getNode(SubOpc, DL, VT, RegV, ConstVal);
+ SDValue CZERO =
DAG.getNode(IsCZERO_NEZ ? RISCVISD::CZERO_NEZ : RISCVISD::CZERO_EQZ,
DL, VT, SubOp, CondV);
- return DAG.getNode(ISD::ADD, DL, VT, CMOV, ConstVal);
+ return DAG.getNode(AddOpc, DL, VT, CZERO, ConstVal);
}
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/171577
More information about the llvm-commits
mailing list