[InstCombine] Allow memcpys from constant memory to readonly nocapture parameters to be elided.
Currently, InstCombine can elide a memcpy from a constant to a local alloca if that alloca is passed as a nocapture parameter to a *function* that's readnone or readonly, but it can't forward the memcpy if the *argument* is marked readonly nocapture, even though readonly guarantees that the callee won't mutate the pointee through that pointer. This patch adds support for detecting and handling such situations, which arise relatively frequently in Rust, a frontend that liberally emits readonly. A more general version of this optimization would use alias analysis to check the call's ModRef info for the pointee, but I was concerned about blowing up compile time, so for now I'm just checking for one of readnone on the function, readonly on the function, or readonly on the parameter. Differential Revision: https://reviews.llvm.org/D136822
Loading
Please sign in to comment