Consider ephemeral calls reading or writing memory as capturing to avoid
memory optimizations that introduce new UB after inlining such calls.
This fixes a mis-compile (see
llvm/test/Transforms/PhaseOrdering/dse-ephemeral-value-captures.ll). The
issue is roughly:
- There's a call to a readonly function that takes a pointer argument and its result is only used by an assume, so the call is considered ephemeral and not capturing.
- Because the call doesn't capture the pointer, it's considered to not read the pointer, causing DSE to remove the store before the call.
- Now the called function gets inlined and there's now a load from the pointer, but the initializing store has been removed
- This leads to SROA replacing the load with undef, which will cause the function to get folded to unreachable by subsequent optimizations.
Alternative to D153464