[llvm] Add test for imperfect loop nest in LoopInterchange (PR #201507)
Rohit Garg via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 4 01:19:36 PDT 2026
https://github.com/rohgarg-qual updated https://github.com/llvm/llvm-project/pull/201507
>From 9e32552483314c41d440833cd00e3c2cf7f3c718 Mon Sep 17 00:00:00 2001
From: rohgarg <rohgarg at qti.qualcomm.com>
Date: Wed, 3 Jun 2026 22:00:42 -0700
Subject: [PATCH] Add test for imperfect loop nest in LoopInterchange
---
.../LoopInterchange/imperfect-loop-nest.ll | 81 +++++++++++++++++++
1 file changed, 81 insertions(+)
create mode 100644 llvm/test/Transforms/LoopInterchange/imperfect-loop-nest.ll
diff --git a/llvm/test/Transforms/LoopInterchange/imperfect-loop-nest.ll b/llvm/test/Transforms/LoopInterchange/imperfect-loop-nest.ll
new file mode 100644
index 0000000000000..f561aadd75804
--- /dev/null
+++ b/llvm/test/Transforms/LoopInterchange/imperfect-loop-nest.ll
@@ -0,0 +1,81 @@
+; RUN: opt -S -passes='loop-interchange' -loop-interchange-profitabilities=ignore < %s
+
+; // Loop nest with multiple loops at same depth
+; for (i = 0; i < 64; i++)
+; for (j = 0; j < 64; j++)
+; for (r = 0; r < 64; r++)
+; C[j][r] = B[j][r] + i;
+;
+; for (k = 0; k < 64; k++)
+; for (l = 0; l < 64; l++)
+; A[l][k] = A[l][k] + 1;
+
+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"
+target triple = "aarch64-unknown-linux-gnueabi"
+
+ at B = dso_local local_unnamed_addr global [64 x [64 x i32]] zeroinitializer, align 4
+ at C = dso_local local_unnamed_addr global [64 x [64 x i32]] zeroinitializer, align 4
+ at A = dso_local local_unnamed_addr global [64 x [64 x i32]] zeroinitializer, align 4
+
+; Function Attrs: nofree norecurse nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none, target_mem0: none, target_mem1: none) uwtable
+define dso_local void @foo(i32 noundef %n, i32 noundef %m, i32 noundef %p) local_unnamed_addr #0 {
+entry:
+ br label %for.cond1.preheader
+
+for.cond1.preheader: ; preds = %entry, %for.inc37
+ %i.058 = phi i32 [ 0, %entry ], [ %inc38, %for.inc37 ]
+ br label %for.cond4.preheader
+
+for.cond4.preheader: ; preds = %for.cond1.preheader, %for.inc13
+ %indvars.iv60 = phi i64 [ 0, %for.cond1.preheader ], [ %indvars.iv.next61, %for.inc13 ]
+ %arrayidx = getelementptr inbounds nuw [64 x i32], ptr @B, i64 %indvars.iv60
+ %arrayidx10 = getelementptr inbounds nuw [64 x i32], ptr @C, i64 %indvars.iv60
+ br label %for.body6
+
+for.body6: ; preds = %for.cond4.preheader, %for.body6
+ %indvars.iv = phi i64 [ 0, %for.cond4.preheader ], [ %indvars.iv.next, %for.body6 ]
+ %arrayidx8 = getelementptr inbounds nuw i32, ptr %arrayidx, i64 %indvars.iv
+ %0 = load i32, ptr %arrayidx8, align 4
+ %add = add nsw i32 %0, %i.058
+ %arrayidx12 = getelementptr inbounds nuw i32, ptr %arrayidx10, i64 %indvars.iv
+ store i32 %add, ptr %arrayidx12, align 4
+ %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
+ %exitcond.not = icmp eq i64 %indvars.iv.next, 64
+ br i1 %exitcond.not, label %for.inc13, label %for.body6
+
+for.inc13: ; preds = %for.body6
+ %indvars.iv.next61 = add nuw nsw i64 %indvars.iv60, 1
+ %exitcond63.not = icmp eq i64 %indvars.iv.next61, 64
+ br i1 %exitcond63.not, label %for.cond19.preheader.preheader, label %for.cond4.preheader
+
+for.cond19.preheader.preheader: ; preds = %for.inc13
+ br label %for.cond19.preheader
+
+for.cond19.preheader: ; preds = %for.cond19.preheader.preheader, %for.inc34
+ %indvars.iv68 = phi i64 [ %indvars.iv.next69, %for.inc34 ], [ 0, %for.cond19.preheader.preheader ]
+ %invariant.gep = getelementptr inbounds nuw i32, ptr @A, i64 %indvars.iv68
+ br label %for.body21
+
+for.body21: ; preds = %for.cond19.preheader, %for.body21
+ %indvars.iv64 = phi i64 [ 0, %for.cond19.preheader ], [ %indvars.iv.next65, %for.body21 ]
+ %gep = getelementptr inbounds nuw [64 x i32], ptr %invariant.gep, i64 %indvars.iv64
+ %1 = load i32, ptr %gep, align 4
+ %add26 = add nsw i32 %1, 1
+ store i32 %add26, ptr %gep, align 4
+ %indvars.iv.next65 = add nuw nsw i64 %indvars.iv64, 1
+ %exitcond67.not = icmp eq i64 %indvars.iv.next65, 64
+ br i1 %exitcond67.not, label %for.inc34, label %for.body21
+
+for.inc34: ; preds = %for.body21
+ %indvars.iv.next69 = add nuw nsw i64 %indvars.iv68, 1
+ %exitcond71.not = icmp eq i64 %indvars.iv.next69, 64
+ br i1 %exitcond71.not, label %for.inc37, label %for.cond19.preheader
+
+for.inc37: ; preds = %for.inc34
+ %inc38 = add nuw nsw i32 %i.058, 1
+ %exitcond72.not = icmp eq i32 %inc38, 64
+ br i1 %exitcond72.not, label %for.end39, label %for.cond1.preheader
+
+for.end39: ; preds = %for.inc37
+ ret void
+}
More information about the llvm-commits
mailing list