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

Ehsan Amiri via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 17 07:05:15 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:

Yeah, I noticed the difference. No I didn't mean getting rid of printing stats, but if you look elsewhere in the code:

1-`ENABLE_STATS_MODE` is not checked for incrementing statistics variables.
2- I don't think we print stats as part of optimization remarks. Stats have their own report, and optimization remarks serve another purpose.

We do want to have stats, but some clean up is needed. They are not managed very well in loop fusion. But if you prefer to merge this and follow up with another patch that is fine. We can do it as well if you are busy.

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


More information about the llvm-commits mailing list