[llvm] [LoopInterchange] Motivating example for interchange. NFC. (PR #171631)

Sebastian Pop via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 11 07:31:44 PST 2025


================
@@ -0,0 +1,569 @@
+; RUN: opt < %s -passes=loop-interchange -cache-line-size=64 -pass-remarks='loop-interchange' -pass-remarks-missed='loop-interchange' -pass-remarks-output=%t -disable-output -S
+; RUN: FileCheck --input-file=%t %s
+
+target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128-Fn32"
+
+; The IR test case below is a full and representative motivating example
+; for loop-interchange containing a more complex loop nest structure that
+; corresponds to this pseudo-code:
+;
+;      for L=1 to NX
+;       for M=1 to NY
+;        for i=1 to NX
+;         for j=1 to NY
+;          for IL=1 to NX
+;           load GlobC(i,IL,L)
+;           load GlobG(i,IL,L)
+;           load GlobE(i,IL,L)
+;           load GlobI(i,IL,L)
+;           for JL=1 to NY
+;            load GlobD(j,JL,M)
+;            load GlobH(j,JL,M)
+;            load GlobF(j,JL,M)
+;            load GlobJ(j,JL,M)
+;            store GlobL(NY*i+j,NY*IL+JL)
+;           End
+;          End
+;         End
+;        End
+;        // Stmt 2
+;        // Stmt 3
+;        // Stmt 4
+;      End
+;     End
+;
+; It is important to note here that this comes from Fortran code, which uses a
+; column-major data layout, so loops 'j' and 'JL' should be interchanged. I.e.
+; in the IR below, basic block JL.body is part of the loop that we would like
+; like to see interchanged as there are 4 loads and 1 store that are
+; unit-strided over 'j', so making 'j' loop the innermost is preferable here.
+;
+; TODO:
+;
+; There are a few issues that prevent loop-interchange to perform its
+; transformation on this test case:
+;
+; 1. LoopNest checks: the first check that is perform is whether loop 'L.header'
+;    and 'M.header' are perfectly nested, which they are not. It needs to be
+;    investigate why the whole loop nest rooted under L is rejected as a
+;    candidate.
+;
+; 2. DependenceAnalysis: it finds this dependency:
+;
+;    Found output dependency between Src and Dst
+;      Src:  store double %46, ptr %48, align 8
+;      Dst:  store double %46, ptr %48, align 8
----------------
sebpop wrote:

This should be "no dependence", as it is the same store.
This will be fixed by adding versioning with runtime checks: we currently keep the dependence relation if we need to attach to it any runtime predicates.

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


More information about the llvm-commits mailing list