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

Ehsan Amiri via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 16 10:53:48 PDT 2026


================
@@ -363,12 +363,15 @@ struct FusionCandidate {
 
   bool reportInvalidCandidate(Statistic &Stat) const {
     using namespace ore;
-    assert(L && Preheader && "Fusion candidate not initialized properly!");
+    ORE.emit(OptimizationRemarkAnalysis(DEBUG_TYPE, "InvalidCandidate",
+                                        L->getStartLoc(), L->getHeader())
+             << "Loop is not a candidate for fusion");
+
 #if LLVM_ENABLE_STATS
     ++Stat;
     ORE.emit(OptimizationRemarkAnalysis(DEBUG_TYPE, Stat.getName(),
-                                        L->getStartLoc(), Preheader)
-             << "[" << Preheader->getParent()->getName() << "]: "
+                                        L->getStartLoc(), L->getHeader())
+             << "[" << L->getHeader()->getParent()->getName() << "]: "
              << "Loop is not a candidate for fusion: " << Stat.getDesc());
 #endif
     return false;
----------------
amehsan wrote:

LGTM, but I would remove checking `LLVM_ENABLE_STATS` macro and the duplicated opt report inside it. 

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


More information about the llvm-commits mailing list