[llvm] [LoopInterchange] Fix overflow in cost calculation (PR #111807)

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 4 10:36:33 PST 2024


================
@@ -0,0 +1,37 @@
+; RUN: opt <  %s  -passes='print<loop-cache-cost>' -disable-output 2>&1 | FileCheck  %s
+
+; For a loop with a very large iteration count, make sure the cost
+; calculation does not overflow:
+;
+; void a(int b) {
+;   for (int c;; c += b)
+;     for (long d = 0; d < -3ULL; d += 2ULL)
+;       A[c][d][d] = 0;
+; }
+
+; CHECK: Loop 'for.cond' has cost = 9223372036854775807
+; CHECK: Loop 'for.body' has cost = 9223372036854775807
+
+ at A = local_unnamed_addr global [11 x [11 x [11 x i32]]] zeroinitializer, align 16
+
+define void @foo(i32 noundef %b) {
+entry:
+  %0 = sext i32 %b to i64
+  br label %for.cond
+
+for.cond:
+  %indvars.iv = phi i64 [ %indvars.iv.next, %for.cond.cleanup ], [ 0, %entry ]
----------------
fhahn wrote:

```suggestion
  %iv = phi i64 [ %indvars.iv.next, %for.cond.cleanup ], [ 0, %entry ]
```

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


More information about the llvm-commits mailing list