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 @@ -10152,9 +10152,30 @@ bool PreferSetCC = N->hasOneUse() && N->use_begin()->getOpcode() == ISD::BRCOND; - SDValue Combined = SimplifySetCC( - N->getValueType(0), N->getOperand(0), N->getOperand(1), - cast(N->getOperand(2))->get(), SDLoc(N), !PreferSetCC); + ISD::CondCode Cond = cast(N->getOperand(2))->get(); + EVT VT = N->getValueType(0); + + // BRCOND(SETCC(FREEZE(a), b)) is equivalent to + // BRCOND(SETCC(a, b)) (both are nondeterministic jumps). + if (PreferSetCC) { + SDValue N0 = N->getOperand(0), N1 = N->getOperand(1); + bool Updated = false; + + if (N0->getOpcode() == ISD::FREEZE && N0.hasOneUse()) { + N0 = N0->getOperand(0); + Updated = true; + } + if (N1->getOpcode() == ISD::FREEZE && N1.hasOneUse()) { + N1 = N1->getOperand(0); + Updated = true; + } + + if (Updated) + return DAG.getSetCC(SDLoc(N), VT, N0, N1, Cond); + } + + SDValue Combined = SimplifySetCC(VT, N->getOperand(0), N->getOperand(1), Cond, + SDLoc(N), !PreferSetCC); if (!Combined) return SDValue(); diff --git a/llvm/test/CodeGen/X86/setcc-freeze.ll b/llvm/test/CodeGen/X86/setcc-freeze.ll --- a/llvm/test/CodeGen/X86/setcc-freeze.ll +++ b/llvm/test/CodeGen/X86/setcc-freeze.ll @@ -4,9 +4,7 @@ define i32 @f(i16* %p) { ; CHECK-LABEL: f: ; CHECK: # %bb.0: -; CHECK-NEXT: movzwl (%rdi), %eax -; CHECK-NEXT: andl $2048, %eax # imm = 0x800 -; CHECK-NEXT: testw %ax, %ax +; CHECK-NEXT: testb $8, 1(%rdi) ; CHECK-NEXT: je .LBB0_1 ; CHECK-NEXT: # %bb.2: # %B ; CHECK-NEXT: movl $20, %eax