[llvm] [Delinearization] Precommit test. NFC. (PR #175173)
Sjoerd Meijer via llvm-commits
llvm-commits at lists.llvm.org
Fri Jan 9 06:17:17 PST 2026
https://github.com/sjoerdmeijer created https://github.com/llvm/llvm-project/pull/175173
This precommits a test for #175158 which should demonstrate that Delinearization succeeds when we extract loop bounds from the global variable definition.
>From 33cafc9dcbb88e01788f4992929a203f80febc6a Mon Sep 17 00:00:00 2001
From: Sjoerd Meijer <smeijer at nvidia.com>
Date: Fri, 9 Jan 2026 06:12:18 -0800
Subject: [PATCH] [Delinearization] Precommit test. NFC.
This precommits a test for #175158 which should demonstrate that
Delinearization succeeds when we extract loop bounds from the global
variable definition.
---
.../Delinearization/global_array_bounds.ll | 52 +++++++++++++++++++
1 file changed, 52 insertions(+)
create mode 100644 llvm/test/Analysis/Delinearization/global_array_bounds.ll
diff --git a/llvm/test/Analysis/Delinearization/global_array_bounds.ll b/llvm/test/Analysis/Delinearization/global_array_bounds.ll
new file mode 100644
index 0000000000000..1e77dff90b86d
--- /dev/null
+++ b/llvm/test/Analysis/Delinearization/global_array_bounds.ll
@@ -0,0 +1,52 @@
+; NOTE: Assertions have been autogenerated by utils/update_analyze_test_checks.py UTC_ARGS: --version 5
+; RUN: opt < %s -passes='print<delinearization>' -disable-output 2>&1 | FileCheck %s
+
+; Pseudo-code:
+;
+; arr[10][20];
+;
+; for i=0 to 10
+; for j=0 to 20
+; a[i][j]; // arr + i*20 + j
+;
+
+ at test_array_10x20 = global [10 x [20 x i32]] zeroinitializer
+
+; Function that accesses a 2D array with dimensions [10][20].
+define void @test_2d_array(i64 %i, i64 %j) {
+; CHECK-LABEL: 'test_2d_array'
+; CHECK-NEXT: Inst: %val = load i32, ptr %ptr, align 4
+; CHECK-NEXT: AccessFunction: {{\{\{}}0,+,80}<nuw><nsw><%for.i>,+,4}<%for.j>
+; CHECK-NEXT: failed to delinearize
+;
+entry:
+ %arr = getelementptr inbounds [10 x [20 x i32]], ptr @test_array_10x20, i32 0, i32 0
+ br label %for.i
+
+for.i:
+ %i.cur = phi i64 [ 0, %entry ], [ %i.next, %for.j.end ]
+ %i.cmp = icmp slt i64 %i.cur, 10
+ br i1 %i.cmp, label %for.j, label %exit
+
+for.j:
+ %j.cur = phi i64 [ 0, %for.i ], [ %j.next, %for.j ]
+
+ ; Compute linear access: arr[i][j] = arr + i*20 + j
+ %i.mul = mul i64 %i.cur, 20
+ %idx = add i64 %i.mul, %j.cur
+ %ptr = getelementptr inbounds i32, ptr %arr, i64 %idx
+
+ ; Load from the computed address
+ %val = load i32, ptr %ptr, align 4
+
+ %j.next = add i64 %j.cur, 1
+ %j.cmp = icmp slt i64 %j.next, 20
+ br i1 %j.cmp, label %for.j, label %for.j.end
+
+for.j.end:
+ %i.next = add i64 %i.cur, 1
+ br label %for.i
+
+exit:
+ ret void
+}
More information about the llvm-commits
mailing list