[PATCH] D123400: [LoopCacheAnalysis] Consider dimension depth of the subscript reference when calculating cost

Bardia Mahjour via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 8 09:18:22 PDT 2022


bmahjour created this revision.
bmahjour added reviewers: congzhe, etiotto, Whitney, LoopOptWG.
bmahjour added a project: LoopOptWG.
Herald added subscribers: steven.zhang, hiraditya, nemanjai.
Herald added a project: All.
bmahjour requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

As described in https://reviews.llvm.org/D122776, the current LoopCacheCost analysis is not able to determine profitable nesting for outer loops of a nest more than 2 levels deep. For example consider the first loop in the existing LIT test `llvm/test/Analysis/LoopCacheAnalysis/PowerPC/matvecmul.ll`. The loop looks like this:

  ;   for (int k=1;k<nz,++k)
  ;      for (int j=1;j<ny,++j)
  ;        for (int i=1;i<nx,++i)
  ;          for (int l=1;l<nb,++l)
  ;            for (int m=1;m<nb,++m)
  ;                 y[k+1][j][i][l] = y[k+1][j][i][l] + b[k][j][i][m][l]*x[k][j][i][m]

and the cost for the `k`,` j` and `i` loops are all calculated to be `30000000000`. The problem is that when considering a subject loop as the inner most loop of the nest, if the access pattern is not consecutive, the cost function returns the trip count of that loop as the estimated number of cache lines accessed. If the trip counts are equal (or unknown in which case we assume a default value of 100) then the costs of the outer loops will be identical. The cost function needs to give more weight to the reference groups that use a function of the loop's IV as a subscript into outer dimensions. This patch tries to do that by multiplying the trip counts of the loops corresponding to subscripts that come between the subject loop and inner dimensions. (ie for a given reference group, the farther away a subscript from the innermost level, the higher the cost of moving the corresponding loop into the innermost position).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D123400

Files:
  llvm/include/llvm/Analysis/LoopCacheAnalysis.h
  llvm/lib/Analysis/LoopCacheAnalysis.cpp
  llvm/test/Analysis/LoopCacheAnalysis/PowerPC/matvecmul.ll
  llvm/test/Analysis/LoopCacheAnalysis/PowerPC/single-store.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D123400.421542.patch
Type: text/x-patch
Size: 7430 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220408/ee4de9df/attachment.bin>


More information about the llvm-commits mailing list