diff --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp --- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp @@ -12230,8 +12230,18 @@ // setcc is very commonly used as an argument to brcond. This pattern // also lend itself to numerous combines and, as a result, it is desired // we keep the argument to a brcond as a setcc as much as possible. - bool PreferSetCC = - N->hasOneUse() && N->use_begin()->getOpcode() == ISD::BRCOND; + bool PreferSetCC = [&]() { + if (!N->hasOneUse()) { + return false; + } + + SDNode *U = *N->use_begin(); + if (U->getOpcode() == ISD::FREEZE && U->hasOneUse()) { + U = *U->use_begin(); + } + + return U->getOpcode() == ISD::BRCOND; + }(); ISD::CondCode Cond = cast(N->getOperand(2))->get(); EVT VT = N->getValueType(0);