[DSE] Remove stores in the same loop iteration
authorDavid Green <david.green@arm.com>
Mon, 31 May 2021 09:22:37 +0000 (10:22 +0100)
committerDavid Green <david.green@arm.com>
Mon, 31 May 2021 09:22:37 +0000 (10:22 +0100)
commit222aeb4d51a46c5a81c9e4ccb16d1d19dd21ec95
tree1984ab809e117a9af06a47d02f1247e682ecb3b9
parent24ee6d3d3c6215db11e9015e94f5f4a9b5a7b750
[DSE] Remove stores in the same loop iteration

DSE will currently only remove stores in the same block unless they can
be guaranteed to be loop invariant. This expands that to any stores that
are in the same Loop, at the same loop level. This should still account
for where AA/MSSA will not handle aliasing between loops, but allow the
dead stores to be removed where they overlap in the same loop iteration.
It requires adding loop info to DSE, but that looks fairly harmless.

The test case this helps is from code like this, which can come up in
certain matrix operations:
  for(i=..)
    dst[i] = 0;
    for(j=..)
      dst[i] += src[i*n+j];

After LICM, this becomes:
for(i=..)
  dst[i] = 0;
  sum = 0;
  for(j=..)
    sum += src[i*n+j];
  dst[i] = sum;

The first store is dead, and with this patch is now removed.

Differntial Revision: https://reviews.llvm.org/D100464
llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
llvm/test/CodeGen/AMDGPU/opt-pipeline.ll
llvm/test/Other/opt-O2-pipeline.ll
llvm/test/Other/opt-O3-pipeline-enable-matrix.ll
llvm/test/Other/opt-O3-pipeline.ll
llvm/test/Other/opt-Os-pipeline.ll
llvm/test/Transforms/DeadStoreElimination/multiblock-loops.ll