[llvm] [LoopFusion] Validate loop structure before creating LoopCandidates (PR #192280)

Ehsan Amiri via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 15 10:13:35 PDT 2026


================
@@ -573,6 +575,14 @@ struct LoopFuser {
   /// Flow Equivalent sets, sorted by dominance.
   void collectFusionCandidates(const LoopVector &LV) {
     for (Loop *L : LV) {
+      // Skip loops that do not have the structure required for fusion (e.g.
+      // loops with indirectbr may lack a preheader). Creating a FusionCandidate
+      // for such loops can lead to reportInvalidCandidate being called with
+      // a null Preheader.
+      if (!L->getLoopPreheader() || !L->getHeader() || !L->getExitingBlock() ||
+          !L->getExitBlock() || !L->getLoopLatch())
+        continue;
----------------
amehsan wrote:

can we have a loop with no header? Loops in LLVM are natural loops, so they must have a header IIUC.

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


More information about the llvm-commits mailing list