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

Madhur Amilkanthwar via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 17 01:48:27 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;
----------------
madhur13490 wrote:

In `ENABLE_STATS_MODE` the remark is printing `Stat.getName()` so it is not really a duplicate opt and printing some new information. If we want to get rid of printing stats altogether, then I believe that is a separate patch.

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


More information about the llvm-commits mailing list