================ @@ -8030,7 +8077,431 @@ SDValue SystemZTargetLowering::combineBSWAP( return SDValue(); } +// Combine IPM sequence for flag output operands. +static bool combineSRL_IPM_CCMask(SDValue &CCReg, int &CCValid, int &CCMask) { + // Convert CCVal to CCMask and update it along with CCValid. + const auto convertCCValToCCMask = [&CCMask, &CCValid](int CCVal) { + bool Invert = false; + if (CCMask == SystemZ::CCMASK_CMP_NE) + Invert = !Invert; + if (CCMask == SystemZ::CCMASK_CMP_EQ || CCMask == SystemZ::CCMASK_CMP_NE) { + CCMask = CCMaskForSystemZCCVal(CCVal); + if (Invert) + CCMask ^= SystemZ::CCMASK_ANY; + CCValid = SystemZ::CCMASK_ANY; + return true; + } else if (CCMask == SystemZ::CCMASK_CMP_LT) { + // CC in range [0, CCVal). + CCMask = ((~0U << (4 - CCVal)) & SystemZ::CCMASK_ANY); + CCValid = SystemZ::CCMASK_ANY; + return true; + } else if (CCMask == SystemZ::CCMASK_CMP_GT) { + // CC in range (CCVal, 3]. + CCMask = (~(~0U << (3 - CCVal))) & SystemZ::CCMASK_ANY; + CCValid = SystemZ::CCMASK_ANY; + return true; + } + return false; + }; + // Check (SRL (IPM (CC))) and update CCReg to combine. + const auto isSRL_IPM_CCSequence = [&CCReg](SDNode *N) { + if (!N || N->getOpcode() != ISD::SRL) + return false; + auto *SRLCount = dyn_cast<ConstantSDNode>(N->getOperand(1)); + if (!SRLCount || SRLCount->getZExtValue() != SystemZ::IPM_CC) + return false; + auto *IPM = N->getOperand(0).getNode(); + if (!IPM || IPM->getOpcode() != SystemZISD::IPM) + return false; + auto *IPMOp0 = IPM->getOperand(0).getNode(); + if (!IPMOp0 || IPMOp0->getNumOperands() < 2) + return false; + auto *RN = dyn_cast<RegisterSDNode>(IPMOp0->getOperand(1)); + // Check if operand 1 is SystemZ::CC. Also, it avoids srl/ipm/tbegin and + // srl/ipm/tend kind of sequences. ---------------- uweigand wrote:
Why is this check needed? The logic should be correct no matter the operand of `IPM`. In fact, we might *want* to optimize these sequences for `tbegin` or `tend` (or, more importantly, some of the vector intrinsics). 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