Coalesce subreg-subreg copies.
[oota-llvm.git] / lib / Analysis / ConstantFolding.cpp
index 59248c9ca0ae7f86f2db6f5220671481df0171c3..7ced848aa1b63a4800cb69a446f059309f1b17d2 100644 (file)
@@ -780,17 +780,20 @@ Constant *llvm::ConstantFoldInstruction(Instruction *I,
       // all operands are constants.
       if (isa<UndefValue>(Incoming))
         continue;
-      // If the incoming value is not a constant, or is a different constant to
-      // the one we saw previously, then give up.
+      // If the incoming value is not a constant, then give up.
       Constant *C = dyn_cast<Constant>(Incoming);
-      if (!C || (CommonValue && C != CommonValue))
+      if (!C)
+        return 0;
+      // Fold the PHI's operands.
+      if (ConstantExpr *NewC = dyn_cast<ConstantExpr>(C))
+        C = ConstantFoldConstantExpression(NewC, TD, TLI);
+      // If the incoming value is a different constant to
+      // the one we saw previously, then give up.
+      if (CommonValue && C != CommonValue)
         return 0;
       CommonValue = C;
     }
 
-    // Fold the PHI's operands.
-    if (ConstantExpr *NewCE = dyn_cast<ConstantExpr>(CommonValue))
-      CommonValue = ConstantFoldConstantExpression(NewCE, TD, TLI);
 
     // If we reach here, all incoming values are the same constant or undef.
     return CommonValue ? CommonValue : UndefValue::get(PN->getType());