[llvm] [RISCV] Lower SELECT's with one constant more efficiently using Zicond (PR #143581)
Ryan Buchner via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 10 15:38:57 PDT 2025
================
@@ -9088,6 +9088,22 @@ SDValue RISCVTargetLowering::lowerSELECT(SDValue Op, SelectionDAG &DAG) const {
return DAG.getNode(ISD::ADD, DL, VT, CMOV, RHSVal);
}
+ // (select c, c1, t) -> (add (czero_nez t - c1, c), c1)
+ // (select c, t, c1) -> (add (czero_eqz t - c1, c), c1)
+ if (isa<ConstantSDNode>(TrueV) ^ isa<ConstantSDNode>(FalseV)) {
+ bool IsCZERO_NEZ = isa<ConstantSDNode>(TrueV);
+ SDValue ConstVal = IsCZERO_NEZ ? TrueV : FalseV;
+ // Efficient only if the constant and its negation fit into `ADDI`
+ if (std::abs(cast<ConstantSDNode>(ConstVal)->getSExtValue()) < 0x800) {
----------------
bababuck wrote:
Can we just use XOR for all the cases (assuming `isInt<12>`)?
https://github.com/llvm/llvm-project/pull/143581
More information about the llvm-commits
mailing list