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 @@ -24969,21 +24969,16 @@ LLD->getBasePtr().getValueType())) return false; - // The loads must not depend on one another. - if (LLD->isPredecessorOf(RLD) || RLD->isPredecessorOf(LLD)) - return false; - // Check that the select condition doesn't reach either load. If so, // folding this will induce a cycle into the DAG. If not, this is safe to // xform, so create a select of the addresses. - SmallPtrSet Visited; SmallVector Worklist; - // Always fail if LLD and RLD are not independent. TheSelect is a - // predecessor to all Nodes in question so we need not search past it. + // The token chain was verified to be identical between RHS and LHD above + // and transitively is a predecessor of all nodes in question. + Visited.insert(LHS.getOperand(0).getNode()); - Visited.insert(TheSelect); Worklist.push_back(LLD); Worklist.push_back(RLD); @@ -24997,13 +24992,14 @@ // predecessor to {RLD, LLD, CondNode}. As we've already compared the // Loads, we only need to check if CondNode is a successor to one of the // loads. We can further avoid this if there's no use of their chain - // value. + // value, because we check about that the only use of the value result + // is the select itself. SDNode *CondNode = TheSelect->getOperand(0).getNode(); Worklist.push_back(CondNode); - if ((LLD->hasAnyUseOfValue(1) && + if ((LLD->hasAnyUseOfValue(0) && SDNode::hasPredecessorHelper(LLD, Visited, Worklist)) || - (RLD->hasAnyUseOfValue(1) && + (RLD->hasAnyUseOfValue(0) && SDNode::hasPredecessorHelper(RLD, Visited, Worklist))) return false; @@ -25023,9 +25019,9 @@ Worklist.push_back(CondLHS); Worklist.push_back(CondRHS); - if ((LLD->hasAnyUseOfValue(1) && + if ((LLD->hasAnyUseOfValue(0) && SDNode::hasPredecessorHelper(LLD, Visited, Worklist)) || - (RLD->hasAnyUseOfValue(1) && + (RLD->hasAnyUseOfValue(0) && SDNode::hasPredecessorHelper(RLD, Visited, Worklist))) return false;