Teach LoopUnswitch not to perform non-trivial unswitching on loops containing converg...
[oota-llvm.git] / lib / Transforms / Scalar / LoopUnswitch.cpp
index 60910bab090e70f9807902b82d571014f5993fe1..6d99caf1dff8bd87628fac41ef98f0bc7499c333 100644 (file)
@@ -500,6 +500,20 @@ bool LoopUnswitch::processCurrentLoop() {
     return true;
   }
 
+  // Do not unswitch loops containing convergent operations, as we might be
+  // making them control dependent on the unswitch value when they were not
+  // before.
+  // FIXME: This could be refined to only bail if the convergent operation is
+  // not already control-dependent on the unswitch value.
+  for (const auto BB : currentLoop->blocks()) {
+    for (const auto &I : *BB) {
+      const auto CI = dyn_cast<CallInst>(&I);
+      if (!CI) continue;
+      if (CI->isConvergent())
+        return false;
+    }
+  }
+
   // Do not do non-trivial unswitch while optimizing for size.
   // FIXME: Use Function::optForSize().
   if (OptimizeForSize ||