@@ -2688,6 +2688,31 @@ bool RISCVTargetLowering::mergeStoresAfterLegalization(EVT VT) const {
26882688 (VT.isFixedLengthVector() && VT.getVectorElementType() == MVT::i1);
26892689}
26902690
2691+ // Disable normalizing for most cases
2692+ // select(N0&N1, X, Y) => select(N0, select(N1, X, Y), Y) and
2693+ // select(N0|N1, X, Y) => select(N0, Y, select(N1, X, Y))
2694+ // If y == 0 and N0 == setcc(eqz || nez) -> czero (select(N1, X, 0), N0)
2695+ bool RISCVTargetLowering::shouldNormalizeToSelectSequence(LLVMContext &, EVT VT,
2696+ SDNode *N) const {
2697+ if (Subtarget.hasStdExtZicond() || Subtarget.hasVendorXVentanaCondOps()) {
2698+ assert(
2699+ N->getOpcode() == ISD::SELECT &&
2700+ "shouldNormalizeTooSelectSequence() called with non-SELECT operation");
2701+ const SDValue &CondV = N->getOperand(0);
2702+ if (CondV.getOpcode() == ISD::SETCC && isNullConstant(N->getOperand(2))) {
2703+ ISD::CondCode CondCode = cast<CondCodeSDNode>(CondV.getOperand(2))->get();
2704+ if (CondCode == ISD::SETNE || CondCode == ISD::SETEQ) {
2705+ return true;
2706+ }
2707+ }
2708+ }
2709+ return false;
2710+ }
2711+
2712+ bool RISCVTargetLowering::hasConditionalZero() const {
2713+ return Subtarget.hasStdExtZicond() || Subtarget.hasVendorXVentanaCondOps();
2714+ }
2715+
26912716bool RISCVTargetLowering::isLegalElementTypeForRVV(EVT ScalarTy) const {
26922717 if (!ScalarTy.isSimple())
26932718 return false;
@@ -15731,6 +15756,35 @@ static SDValue performANDCombine(SDNode *N,
1573115756 if (SDValue V = reverseZExtICmpCombine(N, DAG, Subtarget))
1573215757 return V;
1573315758
15759+ if (Subtarget.hasStdExtZicond() || Subtarget.hasVendorXVentanaCondOps()) {
15760+ auto IsCzeroCompatible = [](const SDValue &Op0,
15761+ const SDValue &Op1) -> bool {
15762+ if (Op0.getValueType() == MVT::i1 && Op1.getOpcode() == ISD::SETCC &&
15763+ isNullConstant(Op1.getOperand(1))) {
15764+ ISD::CondCode CondCode = cast<CondCodeSDNode>(Op1.getOperand(2))->get();
15765+ return CondCode == ISD::SETNE || CondCode == ISD::SETEQ;
15766+ }
15767+ return false;
15768+ };
15769+ // (and (i1) f, (setcc c, 0, ne)) -> (select c, f, 0) -> (czero.nez f, c)
15770+ // (and (i1) f, (setcc c, 0, eq)) -> (select c, 0, f) -> (czero.eqz f, c)
15771+ // (and (setcc c, 0, ne), (i1) g) -> (select c, g, 0) -> (czero.nez g, c)
15772+ // (and (setcc c, 0, eq), (i1) g) -> (select c, 0, g) -> (czero.eqz g, c)
15773+ if (IsCzeroCompatible(N->getOperand(0), N->getOperand(1)) ||
15774+ IsCzeroCompatible(N->getOperand(1), N->getOperand(0))) {
15775+ const bool CzeroOp1 =
15776+ IsCzeroCompatible(N->getOperand(0), N->getOperand(1));
15777+ const SDValue &I1Op = CzeroOp1 ? N->getOperand(0) : N->getOperand(1);
15778+ const SDValue &SetCCOp = CzeroOp1 ? N->getOperand(1) : N->getOperand(0);
15779+
15780+ ISD::CondCode CondCode =
15781+ cast<CondCodeSDNode>(SetCCOp.getOperand(2))->get();
15782+ SDLoc DL(N);
15783+ const SDValue &Condition = SetCCOp.getOperand(0);
15784+ return DAG.getNode(ISD::SELECT, DL, MVT::i1, SetCCOp, I1Op, DAG.getConstant(0, DL, MVT::i1));
15785+ }
15786+ }
15787+
1573415788 if (SDValue V = combineBinOpToReduce(N, DAG, Subtarget))
1573515789 return V;
1573615790 if (SDValue V = combineBinOpOfExtractToReduceTree(N, DAG, Subtarget))
0 commit comments