[PATCH] D104636: [LoopIdiom] [LoopNest] let the pass deal with runtime memset size

Yueh-Ting Chen via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Jul 24 01:08:50 PDT 2021


eopXD added a comment.

SCEV folding is still needed for simple for-loop test case.

  void test(int n, int m, int o, int *ar) {
    for (int i=0; i<n; ++i) {
      for (int j=0; j<m; ++j) {
        int *arr = ar + i * m * o + j * o;
        memset(arr, 0, o * sizeof(int));      
      }
    }
  }

For the inner loop:

  MemsetSizeSCEV: (4 * (sext i32 %o to i64))<nsw>
  PositiveStrideSCEV: (4 * (sext i32 %o to i64))<nsw>
  Calculate NumBytesS = TripCountS * StoreSizeSCEV
    TripCountS: (zext i32 %m to i64)
    StoreSizeSCEV: (4 * (sext i32 %o to i64))<nsw>
    NumBytesS: (4 * (zext i32 %m to i64) * (sext i32 %o to i64))

Then in the outer-loop, to compare MemsetSizeSCEV to the PointerStrideSCEV, the pass should convert `sext` to `zext` for comparison, which is the SCEV folding and runtime check is added.

  MemsetSizeSCEV: (4 * (zext i32 %m to i64) * (sext i32 %o to i64))
  PositiveStrideSCEV: (4 * (sext i32 %m to i64) * (sext i32 %o to i64))
  Try to convert SCEV expression and compare again
    MemsetSCEVConv: (4 * (zext i32 %m to i64) * (zext i32 %o to i64))
    PositiveStrideSCEVConv: (4 * (zext i32 %m to i64) * (zext i32 %o to i64))


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D104636/new/

https://reviews.llvm.org/D104636



More information about the llvm-commits mailing list