================ @@ -8826,15 +9104,49 @@ SDValue SystemZTargetLowering::combineSELECT_CCMASK( int CCMaskVal = CCMask->getZExtValue(); SDValue CCReg = N->getOperand(4); - if (combineCCMask(CCReg, CCValidVal, CCMaskVal)) - return DAG.getNode(SystemZISD::SELECT_CCMASK, SDLoc(N), N->getValueType(0), - N->getOperand(0), N->getOperand(1), - DAG.getTargetConstant(CCValidVal, SDLoc(N), MVT::i32), - DAG.getTargetConstant(CCMaskVal, SDLoc(N), MVT::i32), - CCReg); - return SDValue(); -} + if (!combineCCMask(CCReg, CCValidVal, CCMaskVal, DCI)) + return SDValue(); + + // Handle TrueVal and FalseVal in outermost select_ccmask. + SDValue TrueVal = N->getOperand(0); + SDValue FalseVal = N->getOperand(1); + const auto &&TrueSDVals = simplifyAssumingCCVal(TrueVal, CCReg, DCI); + const auto &&FalseSDVals = simplifyAssumingCCVal(FalseVal, CCReg, DCI); + // There might be cases where TrueSDVals and FalseSDVals are empty as + // TrueVal and FalseVal both are non-constant, and they have already been + // optimized by combineCCMask, we can not take early exit here, just bypass it + // and directly create a new SELECT_CCMASK. + if (!TrueSDVals.empty() && !FalseSDVals.empty()) { + SmallVector<SDValue, 4> MergedSDVals; + for (auto CC : {0, 1, 2, 3}) { + MergedSDVals.emplace_back(((CCMaskVal & (1 << (3 - CC))) != 0) && + ((CCValidVal & (1 << (3 - CC))) != 0) ---------------- uweigand wrote:
CCValid check is redundant - CCMask is guaranteed to be a subset. 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