[llvm] 3d6fe7a - [LoopCacheAnalysis] Use stable_sort() to avoid non-deterministic print output
via llvm-commits
llvm-commits at lists.llvm.org
Sun May 1 21:54:57 PDT 2022
Author: Congzhe Cao
Date: 2022-05-02T00:49:45-04:00
New Revision: 3d6fe7ace8b0a335273162a977439d5521e6548b
URL: https://github.com/llvm/llvm-project/commit/3d6fe7ace8b0a335273162a977439d5521e6548b
DIFF: https://github.com/llvm/llvm-project/commit/3d6fe7ace8b0a335273162a977439d5521e6548b.diff
LOG: [LoopCacheAnalysis] Use stable_sort() to avoid non-deterministic print output
The print output of loop cache analysis sometimes has a non-deterministic order
and therefore we have been using `CHECK-DAG` in its lit tests. This patch changes
the sorting of LoopCosts to llvm::stable_sort() where we compare loop cost numbers
and sort the loops. In case of the same loop cost numbers, llvm::stable_sort() now
would output a deterministic loop order.
Reviewed By: Meinersbur, fhahn, #loopoptwg
Differential Revision: https://reviews.llvm.org/D124725
Added:
Modified:
llvm/include/llvm/Analysis/LoopCacheAnalysis.h
llvm/test/Analysis/LoopCacheAnalysis/PowerPC/LoopnestFixedSize.ll
llvm/test/Analysis/LoopCacheAnalysis/PowerPC/loads-store.ll
llvm/test/Analysis/LoopCacheAnalysis/PowerPC/matmul.ll
llvm/test/Analysis/LoopCacheAnalysis/PowerPC/matvecmul.ll
llvm/test/Analysis/LoopCacheAnalysis/PowerPC/single-store.ll
llvm/test/Analysis/LoopCacheAnalysis/PowerPC/stencil.ll
Removed:
################################################################################
diff --git a/llvm/include/llvm/Analysis/LoopCacheAnalysis.h b/llvm/include/llvm/Analysis/LoopCacheAnalysis.h
index a724a865d49b4..2c1664743e36f 100644
--- a/llvm/include/llvm/Analysis/LoopCacheAnalysis.h
+++ b/llvm/include/llvm/Analysis/LoopCacheAnalysis.h
@@ -243,9 +243,10 @@ class CacheCost {
/// Sort the LoopCosts vector by decreasing cache cost.
void sortLoopCosts() {
- sort(LoopCosts, [](const LoopCacheCostTy &A, const LoopCacheCostTy &B) {
- return A.second > B.second;
- });
+ stable_sort(LoopCosts,
+ [](const LoopCacheCostTy &A, const LoopCacheCostTy &B) {
+ return A.second > B.second;
+ });
}
private:
diff --git a/llvm/test/Analysis/LoopCacheAnalysis/PowerPC/LoopnestFixedSize.ll b/llvm/test/Analysis/LoopCacheAnalysis/PowerPC/LoopnestFixedSize.ll
index f947106dd0c39..fa85b71ce094f 100644
--- a/llvm/test/Analysis/LoopCacheAnalysis/PowerPC/LoopnestFixedSize.ll
+++ b/llvm/test/Analysis/LoopCacheAnalysis/PowerPC/LoopnestFixedSize.ll
@@ -6,8 +6,8 @@ target triple = "powerpc64le-unknown-linux-gnu"
; Check delinearization in loop cache analysis can handle fixed-size arrays.
; The IR is copied from llvm/test/Analysis/DependenceAnalysis/SimpleSIVNoValidityCheckFixedSize.ll
-; CHECK-DAG: Loop 'for.body' has cost = 4186116
-; CHECK-DAG: Loop 'for.body4' has cost = 128898
+; CHECK: Loop 'for.body' has cost = 4186116
+; CHECK: Loop 'for.body4' has cost = 128898
;; #define N 1024
;; #define M 2048
@@ -48,8 +48,8 @@ for.end13: ; preds = %for.inc11
}
-; CHECK-DAG: Loop 'for.body' has cost = 4186116
-; CHECK-DAG: Loop 'for.body4' has cost = 128898
+; CHECK: Loop 'for.body' has cost = 4186116
+; CHECK: Loop 'for.body4' has cost = 128898
define void @t2([2048 x i32]* %a) {
entry:
@@ -83,11 +83,11 @@ for.end13: ; preds = %for.inc11
declare [2048 x i32]* @func_with_returned_arg([2048 x i32]* returned %arg)
-; CHECK-DAG: Loop 'for.body' has cost = 4472886244958208
-; CHECK-DAG: Loop 'for.body4' has cost = 4472886244958208
-; CHECK-DAG: Loop 'for.body8' has cost = 4472886244958208
-; CHECK-DAG: Loop 'for.body12' has cost = 4472886244958208
-; CHECK-DAG: Loop 'for.body16' has cost = 137728168833024
+; CHECK: Loop 'for.body' has cost = 4472886244958208
+; CHECK: Loop 'for.body4' has cost = 4472886244958208
+; CHECK: Loop 'for.body8' has cost = 4472886244958208
+; CHECK: Loop 'for.body12' has cost = 4472886244958208
+; CHECK: Loop 'for.body16' has cost = 137728168833024
;; #define N 1024
diff --git a/llvm/test/Analysis/LoopCacheAnalysis/PowerPC/loads-store.ll b/llvm/test/Analysis/LoopCacheAnalysis/PowerPC/loads-store.ll
index b73abcac98d9c..c5c9e7602e9ba 100644
--- a/llvm/test/Analysis/LoopCacheAnalysis/PowerPC/loads-store.ll
+++ b/llvm/test/Analysis/LoopCacheAnalysis/PowerPC/loads-store.ll
@@ -10,9 +10,9 @@ target triple = "powerpc64le-unknown-linux-gnu"
; A[i][k][j] += B[i][k][j] + C[i][j][k];
; }
-; CHECK-DAG: Loop 'for.i' has cost = 3000000
-; CHECK-DAG: Loop 'for.k' has cost = 2030000
-; CHECK-DAG: Loop 'for.j' has cost = 1060000
+; CHECK: Loop 'for.i' has cost = 3000000
+; CHECK: Loop 'for.k' has cost = 2030000
+; CHECK: Loop 'for.j' has cost = 1060000
define void @foo(i64 %n, i64 %m, i64 %o, i32* %A, i32* %B, i32* %C) {
entry:
diff --git a/llvm/test/Analysis/LoopCacheAnalysis/PowerPC/matmul.ll b/llvm/test/Analysis/LoopCacheAnalysis/PowerPC/matmul.ll
index c7342fe32eebd..6679b1980ddc6 100644
--- a/llvm/test/Analysis/LoopCacheAnalysis/PowerPC/matmul.ll
+++ b/llvm/test/Analysis/LoopCacheAnalysis/PowerPC/matmul.ll
@@ -10,9 +10,9 @@ target triple = "powerpc64le-unknown-linux-gnu"
; C[i][j] = C[i][j] + A[i][k] * B[k][j];
; }
-; CHECK-DAG:Loop 'for.i' has cost = 2010000
-; CHECK-DAG:Loop 'for.k' has cost = 1040000
-; CHECK-DAG:Loop 'for.j' has cost = 70000
+; CHECK:Loop 'for.i' has cost = 2010000
+; CHECK:Loop 'for.k' has cost = 1040000
+; CHECK:Loop 'for.j' has cost = 70000
define void @matmul(i64 %n, i64 %m, i64 %o, i32* %A, i32* %B, i32* %C) {
entry:
diff --git a/llvm/test/Analysis/LoopCacheAnalysis/PowerPC/matvecmul.ll b/llvm/test/Analysis/LoopCacheAnalysis/PowerPC/matvecmul.ll
index 313795251b492..c843337e0c1e1 100644
--- a/llvm/test/Analysis/LoopCacheAnalysis/PowerPC/matvecmul.ll
+++ b/llvm/test/Analysis/LoopCacheAnalysis/PowerPC/matvecmul.ll
@@ -14,11 +14,11 @@ target triple = "powerpc64le-unknown-linux-gnu"
; y[k+1][j][i][l] = y[k+1][j][i][l] + b[k][j][i][m][l]*x[k][j][i][m]
; }
-; CHECK-DAG: Loop 'k_loop' has cost = 30000000000
-; CHECK-DAG: Loop 'j_loop' has cost = 30000000000
-; CHECK-DAG: Loop 'i_loop' has cost = 30000000000
-; CHECK-DAG: Loop 'm_loop' has cost = 10700000000
-; CHECK-DAG: Loop 'l_loop' has cost = 1300000000
+; CHECK: Loop 'k_loop' has cost = 30000000000
+; CHECK: Loop 'j_loop' has cost = 30000000000
+; CHECK: Loop 'i_loop' has cost = 30000000000
+; CHECK: Loop 'm_loop' has cost = 10700000000
+; CHECK: Loop 'l_loop' has cost = 1300000000
%_elem_type_of_double = type <{ double }>
diff --git a/llvm/test/Analysis/LoopCacheAnalysis/PowerPC/single-store.ll b/llvm/test/Analysis/LoopCacheAnalysis/PowerPC/single-store.ll
index cce6731fb2ac3..23bd1e1fdbc9f 100644
--- a/llvm/test/Analysis/LoopCacheAnalysis/PowerPC/single-store.ll
+++ b/llvm/test/Analysis/LoopCacheAnalysis/PowerPC/single-store.ll
@@ -10,9 +10,9 @@ target triple = "powerpc64le-unknown-linux-gnu"
; A[2*i+3][3*j-4][2*k+7] = 1;
; }
-; CHECK-DAG: Loop 'for.i' has cost = 1000000
-; CHECK-DAG: Loop 'for.j' has cost = 1000000
-; CHECK-DAG: Loop 'for.k' has cost = 60000
+; CHECK: Loop 'for.i' has cost = 1000000
+; CHECK: Loop 'for.j' has cost = 1000000
+; CHECK: Loop 'for.k' has cost = 60000
define void @foo(i64 %n, i64 %m, i64 %o, i32* %A) {
entry:
diff --git a/llvm/test/Analysis/LoopCacheAnalysis/PowerPC/stencil.ll b/llvm/test/Analysis/LoopCacheAnalysis/PowerPC/stencil.ll
index 1f1515435e1a0..f2549f4c96f64 100644
--- a/llvm/test/Analysis/LoopCacheAnalysis/PowerPC/stencil.ll
+++ b/llvm/test/Analysis/LoopCacheAnalysis/PowerPC/stencil.ll
@@ -11,8 +11,8 @@ target triple = "powerpc64le-unknown-linux-gnu"
; }
; }
-; CHECK-DAG: Loop 'for.i' has cost = 20600
-; CHECK-DAG: Loop 'for.j' has cost = 800
+; CHECK: Loop 'for.i' has cost = 20600
+; CHECK: Loop 'for.j' has cost = 800
define void @foo(i64 %n, i64 %m, i32* %A, i32* %B, i32* %C) {
entry:
More information about the llvm-commits
mailing list