llvm-project/llvm/lib/Transforms
Nikita Popov 94b8e2ea4e [MemCpyOpt] memset->memcpy forwarding with undef tail
Currently memcpyopt optimizes cases like

    memset(a, byte, N);
    memcpy(b, a, M);

to

    memset(a, byte, N);
    memset(b, byte, M);

if M <= N. Often this allows further simplifications down the line,
which drop the first memset entirely.

This patch extends this optimization for the case where M > N, but we
know that the bytes a[N..M] are undef due to alloca/lifetime.start.

This situation arises relatively often for Rust code, because Rust does
not initialize trailing structure padding and loves to insert redundant
memcpys. This also fixes https://bugs.llvm.org/show_bug.cgi?id=39844.

For the implementation, I'm reusing a bit of code for a similar existing
optimization (direct memcpy of undef). I've also added memset support to
MemDepAnalysis GetLocation -- Instead, getPointerDependencyFrom could be
used, but it seems to make more sense to add this to GetLocation and thus
make the computation cachable.

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

llvm-svn: 348645
2018-12-07 21:16:58 +00:00
..
AggressiveInstCombine [Aggressive InstCombine] Move C bindings to their own header file. 2018-09-05 11:41:12 +00:00
Coroutines [TI removal] Make `getTerminator()` return a generic `Instruction`. 2018-10-15 10:42:50 +00:00
Hello
IPO [HotColdSplitting] Refine definition of unlikelyExecuted 2018-12-07 20:24:04 +00:00
InstCombine [InstCombine] foldICmpWithLowBitMaskedVal(): don't miscompile -1 vector elts 2018-12-06 08:14:24 +00:00
Instrumentation Reapply "Adapt gcov to changes in CFE." 2018-12-06 18:44:48 +00:00
ObjCARC [TI removal] Switch ObjCARC code to directly use the nice range-based 2018-10-18 00:38:34 +00:00
Scalar [MemCpyOpt] memset->memcpy forwarding with undef tail 2018-12-07 21:16:58 +00:00
Utils [CodeExtractor] Store outputs at the first valid insertion point 2018-12-07 03:01:54 +00:00
Vectorize [PM] Port LoadStoreVectorizer to the new pass manager. 2018-12-07 08:23:37 +00:00
CMakeLists.txt Another try to commit 323321 (aggressive instruction combine). 2018-01-25 12:06:32 +00:00
LLVMBuild.txt Another try to commit 323321 (aggressive instruction combine). 2018-01-25 12:06:32 +00:00