Revert "Revert "This patch builds on top of D13378 to handle constant condition.""
[oota-llvm.git] / lib / Analysis / ScalarEvolution.cpp
index 6386082ca91b51b90f96dd062d0b661b08fe205b..3a4de1aec6d1ddc5a79184daa3309e03bdc8f362 100644 (file)
@@ -3904,6 +3904,11 @@ const SCEV *ScalarEvolution::createNodeForSelectOrPHI(Instruction *I,
                                                       Value *Cond,
                                                       Value *TrueVal,
                                                       Value *FalseVal) {
+  // Handle "constant" branch or select. This can occur for instance when a
+  // loop pass transforms an inner loop and moves on to process the outer loop.
+  if (auto *CI = dyn_cast<ConstantInt>(Cond))
+    return getSCEV(CI->isOne() ? TrueVal : FalseVal);
+
   // Try to match some simple smax or umax patterns.
   auto *ICI = dyn_cast<ICmpInst>(Cond);
   if (!ICI)