Remove the optimizations that convert BRCOND and BR_CC into

unconditional branches or fallthroghes. Instcombine/SimplifyCFG
should be simplifying branches with known conditions.

This fixes some problems caused by these transformations not
updating the MachineBasicBlock CFG.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@89017 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Dan Gohman 2009-11-17 00:47:23 +00:00
parent 76e3e50b8a
commit e0f06c78d3

View File

@ -4442,14 +4442,13 @@ SDValue DAGCombiner::visitBRCOND(SDNode *N) {
SDValue Chain = N->getOperand(0); SDValue Chain = N->getOperand(0);
SDValue N1 = N->getOperand(1); SDValue N1 = N->getOperand(1);
SDValue N2 = N->getOperand(2); SDValue N2 = N->getOperand(2);
ConstantSDNode *N1C = dyn_cast<ConstantSDNode>(N1);
// never taken branch, fold to chain // If N is a constant we could fold this into a fallthrough or unconditional
if (N1C && N1C->isNullValue()) // branch. However that doesn't happen very often in normal code, because
return Chain; // Instcombine/SimplifyCFG should have handled the available opportunities.
// unconditional branch // If we did this folding here, it would be necessary to update the
if (N1C && N1C->getAPIntValue() == 1) // MachineBasicBlock CFG, which is awkward.
return DAG.getNode(ISD::BR, N->getDebugLoc(), MVT::Other, Chain, N2);
// fold a brcond with a setcc condition into a BR_CC node if BR_CC is legal // fold a brcond with a setcc condition into a BR_CC node if BR_CC is legal
// on the target. // on the target.
if (N1.getOpcode() == ISD::SETCC && if (N1.getOpcode() == ISD::SETCC &&
@ -4516,22 +4515,18 @@ SDValue DAGCombiner::visitBR_CC(SDNode *N) {
CondCodeSDNode *CC = cast<CondCodeSDNode>(N->getOperand(1)); CondCodeSDNode *CC = cast<CondCodeSDNode>(N->getOperand(1));
SDValue CondLHS = N->getOperand(2), CondRHS = N->getOperand(3); SDValue CondLHS = N->getOperand(2), CondRHS = N->getOperand(3);
// If N is a constant we could fold this into a fallthrough or unconditional
// branch. However that doesn't happen very often in normal code, because
// Instcombine/SimplifyCFG should have handled the available opportunities.
// If we did this folding here, it would be necessary to update the
// MachineBasicBlock CFG, which is awkward.
// Use SimplifySetCC to simplify SETCC's. // Use SimplifySetCC to simplify SETCC's.
SDValue Simp = SimplifySetCC(TLI.getSetCCResultType(CondLHS.getValueType()), SDValue Simp = SimplifySetCC(TLI.getSetCCResultType(CondLHS.getValueType()),
CondLHS, CondRHS, CC->get(), N->getDebugLoc(), CondLHS, CondRHS, CC->get(), N->getDebugLoc(),
false); false);
if (Simp.getNode()) AddToWorkList(Simp.getNode()); if (Simp.getNode()) AddToWorkList(Simp.getNode());
ConstantSDNode *SCCC = dyn_cast_or_null<ConstantSDNode>(Simp.getNode());
// fold br_cc true, dest -> br dest (unconditional branch)
if (SCCC && !SCCC->isNullValue())
return DAG.getNode(ISD::BR, N->getDebugLoc(), MVT::Other,
N->getOperand(0), N->getOperand(4));
// fold br_cc false, dest -> unconditional fall through
if (SCCC && SCCC->isNullValue())
return N->getOperand(0);
// fold to a simpler setcc // fold to a simpler setcc
if (Simp.getNode() && Simp.getOpcode() == ISD::SETCC) if (Simp.getNode() && Simp.getOpcode() == ISD::SETCC)
return DAG.getNode(ISD::BR_CC, N->getDebugLoc(), MVT::Other, return DAG.getNode(ISD::BR_CC, N->getDebugLoc(), MVT::Other,