This is an archive of the discontinued LLVM Phabricator instance.

[DSE] Support redundant stores eliminated by memset.
ClosedPublic

Authored by fhahn on Oct 22 2021, 9:04 AM.

Details

Summary

This patch adds support to remove stores that write the same value
as earlier memesets.

It uses isOverwrite to check that a memset completely overwrites a later
store. The candidate store must store the same bytewise value as the
byte stored by the memset.

Improvements of dse.NumRedundantStores on MultiSource/CINT2006/CPF2006
on X86 with -O3:

test-suite...oxyApps-C++/miniFE/miniFE.test     1.00                           5.00             400.0%
test-suite...marks/7zip/7zip-benchmark.test     2.00                           8.00             300.0%
test-suite...lications/sqlite3/sqlite3.test     2.00                           7.00             250.0%
test-suite...lications/ClamAV/clamscan.test     1.00                           2.00             100.0%
test-suite.../CINT2006/403.gcc/403.gcc.test     7.00                          11.00             57.1%
test-suite...006/447.dealII/447.dealII.test    33.00                          51.00             54.5%
test-suite...0.perlbench/400.perlbench.test     2.00                           3.00             50.0%
test-suite.../Benchmarks/Bullet/bullet.test    12.00                          16.00             33.3%
test-suite.../Applications/lemon/lemon.test     5.00                           6.00             20.0%
test-suite...DOE-ProxyApps-C/CoMD/CoMD.test     6.00                           7.00             16.7%
test-suite...pplications/oggenc/oggenc.test     7.00                           8.00             14.3%
test-suite...3.xalancbmk/483.xalancbmk.test    62.00                          67.00              8.1%
test-suite...T2006/458.sjeng/458.sjeng.test    NaN                             1.00              nan%
test-suite...CFP2006/444.namd/444.namd.test    NaN                             1.00              nan%
test-suite...nsumer-jpeg/consumer-jpeg.test    NaN                             3.00              nan%
test-suite...rks/tramp3d-v4/tramp3d-v4.test    NaN                            13.00              nan%
test-suite...oxyApps-C/miniGMG/miniGMG.test    NaN                            25.00              nan%

Motivating C test case https://clang.godbolt.org/z/dfEnv7f5x:

#include <string.h>
void foo(int** ptr, int *foo) {
    memset(ptr, 0, 128);
    ptr[1] = foo;
    ptr[2] = NULL;
}

Diff Detail

Event Timeline

fhahn created this revision.Oct 22 2021, 9:04 AM
fhahn requested review of this revision.Oct 22 2021, 9:04 AM
Herald added a project: Restricted Project. · View Herald TranscriptOct 22 2021, 9:04 AM
nikic accepted this revision.Oct 23 2021, 6:23 AM

LGTM

This revision is now accepted and ready to land.Oct 23 2021, 6:23 AM
xbolva00 added inline comments.
llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
1963

Shouldnt this condition also handle pr50339 testcase in stores-of-existing-values.ll?

fhahn updated this revision to Diff 383494.Oct 29 2021, 1:56 PM

rebase so this can be landed without the preceding patches.

This revision was landed with ongoing or failed builds.Oct 29 2021, 2:21 PM
This revision was automatically updated to reflect the committed changes.