[function-attrs] Refactor code to handle shorter code with early exits.
[oota-llvm.git] / lib / Transforms / InstCombine / InstructionCombining.cpp
index 69a2661f031257c83c394d8f365e99b5026dd40e..b51ec291f9134bc6556e5d3eff8ab8138450cdf4 100644 (file)
@@ -1453,8 +1453,13 @@ Instruction *InstCombiner::visitGetElementPtrInst(GetElementPtrInst &GEP) {
       }
     }
 
-    GetElementPtrInst *NewGEP = cast<GetElementPtrInst>(Op1->clone());
+    // If not all GEPs are identical we'll have to create a new PHI node.
+    // Check that the old PHI node has only one use so that it will get
+    // removed.
+    if (DI != -1 && !PN->hasOneUse())
+      return nullptr;
 
+    GetElementPtrInst *NewGEP = cast<GetElementPtrInst>(Op1->clone());
     if (DI == -1) {
       // All the GEPs feeding the PHI are identical. Clone one down into our
       // BB so that it can be merged with the current GEP.