[llvm] [LoopFusion] Drop duplicate write-write dependence check (NFC) (PR #203173)

Madhur Amilkanthwar via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 10 22:10:19 PDT 2026


https://github.com/madhur13490 created https://github.com/llvm/llvm-project/pull/203173

`dependencesAllowFusion()` re-tested every FC0-write vs FC1-write pair in the second loop nest, duplicating the checks already done in the first. Iterate only the remaining FC0-read vs FC1-write pairs; the set of checked dependences (W0xW1, W0xR1, R0xW1) is unchanged.

>From ae35aa0135cda72dcf3672081cdf6927c3ef711f Mon Sep 17 00:00:00 2001
From: Madhur Amilkanthwar <madhura at nvidia.com>
Date: Fri, 5 Jun 2026 01:29:53 -0700
Subject: [PATCH] [LoopFusion] Drop duplicate write-write dependence check
 (NFC)

`dependencesAllowFusion()` re-tested every FC0-write vs FC1-write pair in
the second loop nest, duplicating the checks already done in the first.
Iterate only the remaining FC0-read vs FC1-write pairs; the set of
checked dependences (W0xW1, W0xR1, R0xW1) is unchanged.
---
 llvm/lib/Transforms/Scalar/LoopFuse.cpp | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/llvm/lib/Transforms/Scalar/LoopFuse.cpp b/llvm/lib/Transforms/Scalar/LoopFuse.cpp
index 2712b45d2c6cf..e15a1398d1291 100644
--- a/llvm/lib/Transforms/Scalar/LoopFuse.cpp
+++ b/llvm/lib/Transforms/Scalar/LoopFuse.cpp
@@ -1171,16 +1171,13 @@ struct LoopFuser {
         }
     }
 
-    for (Instruction *WriteL1 : FC1.MemWrites) {
-      for (Instruction *WriteL0 : FC0.MemWrites)
-        if (!dependencesAllowFusion(FC0, FC1, *WriteL0, *WriteL1)) {
-          return false;
-        }
-      for (Instruction *ReadL0 : FC0.MemReads)
+    // Write-write and write-read pairs are already covered above; only the
+    // read-before-write pairs from FC0 reads to FC1 writes remain.
+    for (Instruction *ReadL0 : FC0.MemReads)
+      for (Instruction *WriteL1 : FC1.MemWrites)
         if (!dependencesAllowFusion(FC0, FC1, *ReadL0, *WriteL1)) {
           return false;
         }
-    }
 
     // Walk through all uses in FC1. For each use, find the reaching def. If the
     // def is located in FC0 then it is not safe to fuse.



More information about the llvm-commits mailing list