diff --git a/llvm/lib/Target/SystemZ/SystemZISelLowering.cpp b/llvm/lib/Target/SystemZ/SystemZISelLowering.cpp index 06501b745b3f7..eb93024bed35c 100644 --- a/llvm/lib/Target/SystemZ/SystemZISelLowering.cpp +++ b/llvm/lib/Target/SystemZ/SystemZISelLowering.cpp @@ -8673,15 +8673,17 @@ SmallVector static simplifyAssumingCCVal(SDValue &Val, SDValue &CC, int CCValidVal = CCValid->getZExtValue(); int CCMaskVal = CCMask->getZExtValue(); - const auto &&TrueSDVals = simplifyAssumingCCVal(TrueVal, CC, DAG); - const auto &&FalseSDVals = simplifyAssumingCCVal(FalseVal, CC, DAG); - if (TrueSDVals.empty() || FalseSDVals.empty()) - return {}; + // Pruning search tree early - Moving CC test and combineCCMask ahead of + // recursive call to simplifyAssumingCCVal. SDValue Op4CCReg = Val.getOperand(4); if (Op4CCReg != CC) combineCCMask(Op4CCReg, CCValidVal, CCMaskVal, DAG); if (Op4CCReg != CC) return {}; + const auto &&TrueSDVals = simplifyAssumingCCVal(TrueVal, CC, DAG); + const auto &&FalseSDVals = simplifyAssumingCCVal(FalseVal, CC, DAG); + if (TrueSDVals.empty() || FalseSDVals.empty()) + return {}; SmallVector MergedSDVals; for (auto &CCVal : {0, 1, 2, 3}) MergedSDVals.emplace_back(((CCMaskVal & (1 << (3 - CCVal))) != 0)