[InstCombine] Eliminate stores to constant memory
authorPhilip Reames <listmail@philipreames.com>
Mon, 22 Apr 2019 20:28:19 +0000 (20:28 +0000)
committerPhilip Reames <listmail@philipreames.com>
Mon, 22 Apr 2019 20:28:19 +0000 (20:28 +0000)
commitd748689c7f718f531871bb44b5da05888c3c0301
tree8740bf44aafb4cf78a6212316839e69950bd693d
parent2a27af82379e854ee1b0c5aa7fad6b430eab4b55
[InstCombine] Eliminate stores to constant memory

If we have a store to a piece of memory which is known constant, then we know the store must be storing back the same value. As a result, the store (or memset, or memmove) must either be down a dead path, or a noop. In either case, it is valid to simply remove the store.

The motivating case for this involves a memmove to a buffer which is constant down a path which is dynamically dead.

Note that I'm choosing to implement the less aggressive of two possible semantics here. We could simply say that the store *is undefined*, and prune the path. Consensus in the review was that the more aggressive form might be a good follow on change at a later date.

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

llvm-svn: 358919
llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
llvm/test/Transforms/InstCombine/memcpy.ll
llvm/test/Transforms/InstCombine/memmove.ll
llvm/test/Transforms/InstCombine/memset.ll
llvm/test/Transforms/InstCombine/store.ll