MemCpyOpt can shorten a memset if it is later partially overwritten by a memcpy. It checks that the destination is not read in between, but we also need to make sure that the destination cannot be observed via unwinding.
As a side-note, at least for the constant size case this transform should really be performed by DSE, and it does have some support for this (isShortenableAtTheBeginning), but apparently doesn't catch the memset+memcpy combination.
clang-format: please reformat the code
- for (const Instruction &I : make_range(MemSet->getIterator(), - MemCpy->getIterator())) { + for (const Instruction &I : + make_range(MemSet->getIterator(), MemCpy->getIterator())) {