[llvm] [LoopFusion] Perform cheaper dependency check first (NFCI) (PR #228718)

Ehsan Amiri via llvm-commits llvm-commits at lists.llvm.org
Sat Oct 3 07:44:04 PDT 2026


https://github.com/amehsan created https://github.com/llvm/llvm-project/pull/228718

If two stores write the same SSA value to memory, we can skip DA checks. This change of order has a significant impact on compile time of SingleSource/Benchmarks/Misc/himenobmtxpa.c in test suite when fusion runs with no cost model.

>From 84a5c33f5cafab32ccb389a211b67d76b00e2021 Mon Sep 17 00:00:00 2001
From: Ehsan Amiri <ehsan.amiri at huawei.com>
Date: Sat, 3 Oct 2026 10:39:15 -0400
Subject: [PATCH] [LoopFusion] Perform cheaper dependency check first (NFCI)

If two stores write the same SSA value to memory, we can skip DA checks.
This change of order has a significant impact on compile time of
SingleSource/Benchmarks/Misc/himenobmtxpa.c in test suite when fusion
runs with no cost model.
---
 llvm/lib/Transforms/Scalar/LoopFuse.cpp | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/llvm/lib/Transforms/Scalar/LoopFuse.cpp b/llvm/lib/Transforms/Scalar/LoopFuse.cpp
index 20b05ce6a1302f6..c819ea49246d338 100644
--- a/llvm/lib/Transforms/Scalar/LoopFuse.cpp
+++ b/llvm/lib/Transforms/Scalar/LoopFuse.cpp
@@ -1193,9 +1193,6 @@ struct LoopFuser {
       LLVM_DEBUG(dbgs() << "Check dep: " << I0 << " vs " << I1 << "\n");
     }
 #endif
-    auto DepResult = DI.depends(&I0, &I1);
-    if (!DepResult)
-      return true;
     // If two stores write the same SSA value, fusion is safe regardless of
     // aliasing - writing the same value twice is idempotent.
     if (isa<StoreInst>(I0) && isa<StoreInst>(I1)) {
@@ -1204,6 +1201,9 @@ struct LoopFuser {
       if (S0->getValueOperand() == S1->getValueOperand())
         return true;
     }
+    auto DepResult = DI.depends(&I0, &I1);
+    if (!DepResult)
+      return true;
 #ifndef NDEBUG
     if (VerboseFusionDebugging) {
       LLVM_DEBUG(dbgs() << "DA res: "; DepResult->dump(dbgs());



More information about the llvm-commits mailing list