================ @@ -2837,8 +2837,34 @@ void SelectionDAGBuilder::visitBr(const BranchInst &I) { Opcode = Instruction::And; else if (match(BOp, m_LogicalOr(m_Value(BOp0), m_Value(BOp1)))) Opcode = Instruction::Or; - - if (Opcode && + auto &TLI = DAG.getTargetLoweringInfo(); + const auto checkSRLIPM = [&TLI](const SDValue &Op) { + if (!Op.getNumOperands()) + return false; + SDValue OpVal = Op.getOperand(0); + SDNode *N = OpVal.getNode(); + if (N && N->getOpcode() == ISD::SRL) + return TLI.canLowerSRL_IPM_Switch(OpVal); + else if (N && OpVal.getNumOperands() && + (N->getOpcode() == ISD::AND || N->getOpcode() == ISD::OR)) { + SDValue OpVal1 = OpVal.getOperand(0); + SDNode *N1 = OpVal1.getNode(); + if (N1 && N1->getOpcode() == ISD::SRL) + return TLI.canLowerSRL_IPM_Switch(OpVal1); + } + return false; + }; + // Incoming IR here is straight line code, FindMergedConditions splits + // condition code sequence across Basic Block. DAGCombiner can't combine + // across Basic Block. Identify SRL/IPM/CC sequence for SystemZ and avoid + // transformation in FindMergedConditions. + bool BrSrlIPM = false; + if (NodeMap.count(BOp0) && NodeMap[BOp0].getNode()) { + BrSrlIPM |= checkSRLIPM(getValue(BOp0)); + if (NodeMap.count(BOp1) && NodeMap[BOp1].getNode()) + BrSrlIPM &= checkSRLIPM(getValue(BOp1)); + } ---------------- uweigand wrote:
This is already better than a target check, but there's still a whole lot of implicitly target-specific code here. There really shouldn't be a generic callback `canLowerSRL_IPM_Switch` - that even explicitly refers to SystemZ instruction names! If there's target-specific behavior needed here, this should be better abstracted. Note that I see there's already a target hook to guide whether or not this transformation should be performed: the `getJumpConditionMergingParams` callback that provides input to the `shouldKeepJumpConditionsTogether`. I think you should investigate whether we can create a SystemZ-specific implementation of that callback that has the desired effect of inhibiting this transformation in the cases we care about. That should then work without any common-code change to this function. 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