diff --git a/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp b/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp index e5266c294f8..285f810bfbe 100644 --- a/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp +++ b/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp @@ -852,7 +852,14 @@ static BasicBlock *IsOnlyUsedInOneBasicBlock(Argument *A) { ++UI) if (isa(*UI) || cast(*UI)->getParent() != BB) return 0; // Disagreement among the users? - return BB; + + // Okay, there is a single BB user. Only permit this optimization if this is + // the entry block, otherwise, we might sink argument loads into loops and + // stuff. Later, when we have global instruction selection, this won't be an + // issue clearly. + if (BB == BB->getParent()->begin()) + return BB; + return 0; } void SelectionDAGISel::