[llvm] 5e004fb - [LoopCacheAnalysis][NFC] Add a test case for improved loop cache analysis cost calculation

via llvm-commits llvm-commits at lists.llvm.org
Wed May 4 14:13:45 PDT 2022


Author: Congzhe Cao
Date: 2022-05-04T17:13:10-04:00
New Revision: 5e004fb787698440a387750db7f8028e7cb14cfc

URL: https://github.com/llvm/llvm-project/commit/5e004fb787698440a387750db7f8028e7cb14cfc
DIFF: https://github.com/llvm/llvm-project/commit/5e004fb787698440a387750db7f8028e7cb14cfc.diff

LOG: [LoopCacheAnalysis][NFC] Add a test case for improved loop cache analysis cost calculation

Added a motivating test case for D123400 where the loopnest has a
suboptimal loop order j-i-k. After D123400 we ensure that the order
of loop cache analysis output is loop i-j-k, despite the suboptimal
order in the original loopnest.

Reviewed By: bmahjour, #loopoptwg

Differential Revision: https://reviews.llvm.org/D122776

Added: 
    

Modified: 
    llvm/test/Analysis/LoopCacheAnalysis/PowerPC/single-store.ll

Removed: 
    


################################################################################
diff  --git a/llvm/test/Analysis/LoopCacheAnalysis/PowerPC/single-store.ll b/llvm/test/Analysis/LoopCacheAnalysis/PowerPC/single-store.ll
index 8aa247b867385..24d8e932a504b 100644
--- a/llvm/test/Analysis/LoopCacheAnalysis/PowerPC/single-store.ll
+++ b/llvm/test/Analysis/LoopCacheAnalysis/PowerPC/single-store.ll
@@ -75,3 +75,80 @@ for.end:                                          ; preds = %for.end.loopexit, %
   ret void
 }
 
+; Loop i is supposed to have the largest cost and be placed
+; as the outermost loop. This test 
diff ers from foo() since the
+; loopnest has a suboptimal order j-i-k.
+; After D123400 we ensure that the order of loop cache analysis output
+; is loop i-j-k, despite the suboptimal order in the original loopnest.
+;
+; void foo(long n, long m, long o, int A[n][m][o]) {
+;   for (long j = 0; j < m; j++)
+;     for (long i = 0; i < n; i++)
+;       for (long k = 0; k < o; k++)
+;         A[2*i+3][2*j-4][2*k+7] = 1;
+; }
+
+; CHECK: Loop 'for.i' has cost = 100000000
+; CHECK-NEXT: Loop 'for.j' has cost = 1000000
+; CHECK-NEXT: Loop 'for.k' has cost = 60000
+
+define void @foo2(i64 %n, i64 %m, i64 %o, i32* %A) {
+entry:
+  %cmp32 = icmp sgt i64 %n, 0
+  %cmp230 = icmp sgt i64 %m, 0
+  %cmp528 = icmp sgt i64 %o, 0
+  br i1 %cmp32, label %for.cond1.preheader.lr.ph, label %for.end
+
+for.cond1.preheader.lr.ph:                        ; preds = %entry
+  br i1 %cmp230, label %for.j.preheader, label %for.end
+
+for.j.preheader:                                  ; preds = %for.cond1.preheader.lr.ph
+  br i1 %cmp528, label %for.j.preheader.split, label %for.end
+
+for.j.preheader.split:                            ; preds = %for.j.preheader
+  br label %for.j
+
+for.i:                                            ; preds = %for.inci, %for.j
+  %i = phi i64 [ %inci, %for.inci ], [ 0, %for.j ]
+  %mul8 = shl i64 %i, 1
+  %add9 = add nsw i64 %mul8, 3
+  %0 = mul i64 %add9, %m
+  %sub = add i64 %0, -4
+  %mul7 = mul nsw i64 %j, 2
+  %tmp = add i64 %sub, %mul7
+  %tmp27 = mul i64 %tmp, %o
+  br label %for.k
+
+for.j:                                            ; preds = %for.incj, %for.j.preheader.split
+  %j = phi i64 [ %incj, %for.incj ], [ 0, %for.j.preheader.split ]
+  br label %for.i
+
+for.k:                                            ; preds = %for.k, %for.i
+  %k = phi i64 [ 0, %for.i ], [ %inck, %for.k ]
+
+  %mul = mul nsw i64 %k, 2
+  %arrayidx.sum = add i64 %mul, 7
+  %arrayidx10.sum = add i64 %arrayidx.sum, %tmp27
+  %arrayidx11 = getelementptr inbounds i32, i32* %A, i64 %arrayidx10.sum
+  store i32 1, i32* %arrayidx11, align 4
+
+  %inck = add nsw i64 %k, 1
+  %exitcond.us = icmp eq i64 %inck, %o
+  br i1 %exitcond.us, label %for.inci, label %for.k
+
+for.incj:                                         ; preds = %for.inci
+  %incj = add nsw i64 %j, 1
+  %exitcond54.us = icmp eq i64 %incj, %m
+  br i1 %exitcond54.us, label %for.end.loopexit, label %for.j
+
+for.inci:                                         ; preds = %for.k
+  %inci = add nsw i64 %i, 1
+  %exitcond55.us = icmp eq i64 %inci, %n
+  br i1 %exitcond55.us, label %for.incj, label %for.i
+
+for.end.loopexit:                                 ; preds = %for.incj
+  br label %for.end
+
+for.end:                                          ; preds = %for.end.loopexit, %for.cond1.preheader.lr.ph, %entry
+  ret void
+}


        


More information about the llvm-commits mailing list