[llvm] [IfConversion] Fix bug related to !HasFallThrough (PR #145471)

Eli Friedman via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 24 10:04:09 PDT 2025


================
@@ -397,6 +404,24 @@ namespace {
       return BBI.IsBrAnalyzable && BBI.TrueBB == nullptr;
     }
 
+    /// Returns true if Block is known not to fallthrough to the following BB.
+    bool blockNeverFallThrough(BBInfo &BBI) const {
+      // Trust "HasFallThrough" if we could analyze branches.
+      if (BBI.IsBrAnalyzable)
+        return !BBI.HasFallThrough;
+      // Empty successor list implies that there is no fallthrough.
+      if (BBI.BB->succ_empty())
+        return true;
+      // If the textual successor isn't in the successor list, then there is no
+      // fallthrough.
+      MachineFunction::iterator PI = BBI.BB->getIterator();
+      MachineFunction::iterator I = std::next(PI);
+      if (I != BBI.BB->getParent()->end() && !PI->isSuccessor(&*I))
----------------
efriedma-quic wrote:

`I == BBI.BB->getParent()->end()` implies this is the last block of the function, so it can't fallthrough.

https://github.com/llvm/llvm-project/pull/145471


More information about the llvm-commits mailing list