@@ -9786,22 +9786,17 @@ SDValue RISCVTargetLowering::lowerSELECT(SDValue Op, SelectionDAG &DAG) const {
97869786 SDValue ConstVal = IsCZERO_NEZ ? TrueV : FalseV;
97879787 SDValue RegV = IsCZERO_NEZ ? FalseV : TrueV;
97889788 int64_t RawConstVal = cast<ConstantSDNode>(ConstVal)->getSExtValue();
9789- // Fall back to XORI if Const == -0x800
9790- if (RawConstVal == -0x800) {
9791- SDValue XorOp = DAG.getNode(ISD::XOR, DL, VT, RegV, ConstVal);
9792- SDValue CMOV =
9793- DAG.getNode(IsCZERO_NEZ ? RISCVISD::CZERO_NEZ : RISCVISD::CZERO_EQZ,
9794- DL, VT, XorOp, CondV);
9795- return DAG.getNode(ISD::XOR, DL, VT, CMOV, ConstVal);
9796- }
97979789 // Efficient only if the constant and its negation fit into `ADDI`
97989790 // Prefer Add/Sub over Xor since can be compressed for small immediates
97999791 if (isInt<12>(RawConstVal)) {
9800- SDValue SubOp = DAG.getNode(ISD::SUB, DL, VT, RegV, ConstVal);
9801- SDValue CMOV =
9792+ // Fall back to XORI if Const == -0x800 since we don't have SUBI.
9793+ unsigned SubOpc = (RawConstVal == -0x800) ? ISD::XOR : ISD::SUB;
9794+ unsigned AddOpc = (RawConstVal == -0x800) ? ISD::XOR : ISD::ADD;
9795+ SDValue SubOp = DAG.getNode(SubOpc, DL, VT, RegV, ConstVal);
9796+ SDValue CZERO =
98029797 DAG.getNode(IsCZERO_NEZ ? RISCVISD::CZERO_NEZ : RISCVISD::CZERO_EQZ,
98039798 DL, VT, SubOp, CondV);
9804- return DAG.getNode(ISD::ADD , DL, VT, CMOV , ConstVal);
9799+ return DAG.getNode(AddOpc , DL, VT, CZERO , ConstVal);
98059800 }
98069801 }
98079802
0 commit comments