[llvm] [RISCV] Lower SELECT's with one constant more efficiently using Zicond (PR #143581)
Mikhail Gudim via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 11 11:12:18 PDT 2025
================
@@ -9088,6 +9088,32 @@ 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;
+ SDValue RegV = IsCZERO_NEZ ? FalseV : TrueV;
+ int64_t RawConstVal = cast<ConstantSDNode>(ConstVal)->getSExtValue();
+ // Fall back to XORI if Const == -0x800
+ if (RawConstVal == -0x800) {
----------------
mgudim wrote:
why do we do this only for -0x800?
is this not always true?
select cond, c1, t -> xor(c1, czero_nez(xor(t, c1), cond))
https://github.com/llvm/llvm-project/pull/143581
More information about the llvm-commits
mailing list