================ @@ -8702,61 +8738,264 @@ SDValue SystemZTargetLowering::combineSETCC( return SDValue(); } +static SmallSet<int, 4> convertCCMaskToCCValsSet(int Mask) { + SmallSet<int, 4> CCVals; + size_t Pos = 0; + while (Mask) { + if (Mask & 0x1) + CCVals.insert(3 - Pos); + Mask >>= 1; + ++Pos; + } + return CCVals; +} + +static std::pair<SDValue, int> findCCUse(const SDValue &Val) { + auto *N = Val.getNode(); + if (!N) + return {Val, SystemZ::CCMASK_NONE}; + if (isa<ConstantSDNode>(Val)) + return std::make_pair(SDValue(), SystemZ::CCMASK_NONE); + else if (N->getOpcode() == ISD::CopyFromReg && N->getNumOperands() > 1) { + if (auto *RN = cast<RegisterSDNode>(N->getOperand(1))) { + if (RN->getReg() == SystemZ::CC) + return {Val, SystemZ::CCMASK_ANY}; + } + } else if (N->getOpcode() == SystemZISD::IPM) + return std::make_pair(N->getOperand(0), SystemZ::CCMASK_ANY); + else if (N->getOpcode() == ISD::SRL) + return findCCUse(N->getOperand(0)); + else if (N->getOpcode() == SystemZISD::ICMP) + return findCCUse(N->getOperand(0)); + else if (N->getOpcode() == SystemZISD::TM) + return findCCUse(N->getOperand(0)); + else if (N->getOpcode() == SystemZISD::SELECT_CCMASK) { + SDValue SelectCCReg = N->getOperand(4); + auto [OpCC, OpCCValid] = findCCUse(SelectCCReg); + auto *OpCCNode = OpCC.getNode(); + if (OpCCNode && OpCCNode != SelectCCReg.getNode()) + return std::make_pair(OpCC, OpCCValid); + auto *CCValid = dyn_cast<ConstantSDNode>(N->getOperand(2)); + if (CCValid) + return std::make_pair(SelectCCReg, CCValid->getZExtValue()); + } else if (N->getOpcode() == ISD::ADD || N->getOpcode() == ISD::AND || + N->getOpcode() == ISD::OR || N->getOpcode() == ISD::XOR || + N->getOpcode() == ISD::AND) { + auto [Op0CC, Op0CCValid] = findCCUse(N->getOperand(0)); + if (isa<ConstantSDNode>(N->getOperand(1))) + return std::make_pair(Op0CC, Op0CCValid); + auto [Op1CC, Op1CCValid] = findCCUse(N->getOperand(1)); + auto *N0 = Op0CC.getNode(), *N1 = Op1CC.getNode(); + if (N0 && N1 && N0 == N1 && Op0CCValid == Op1CCValid) + return std::make_pair(Op0CC, Op0CCValid); ---------------- uweigand wrote:
I'm not sure it is necessary to always recurse into both sides. I think we should just return the first CC we find. https://github.com/llvm/llvm-project/pull/125970 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits