This patch extends the code that walks memory defs upwards to find
clobbering accesses to also try to optimize the clobbering defining
access.
We should be able to find set the optimized access of our starting def
(KillingDef), if the following holds:
- It is the first call of getDomMemoryDef for KillingDef (so Current == KillingDef->getDefiningAccess().
- No potentially aliasing defs are skipped.
Then if a (partly) aliasing def is encountered, it can be used as
optimized access for KillingDef. No further optimizations can be
applied to KillingDef.
I'd appreciate a careful look, as the existing documentation is not too
clear on what is expected for optimized accesses.
The motivation for this patch is to use the optimized accesses to cover
more cases of redundant stores as follow-up to D111727.
Looking at how canSkipDef() is defined, I think this is wrong on two fronts:
First, canSkipDef() skips any mayThrow() instruction if !DefVisibleToCaller. But what if this is a non-nounwind call that clobbers KillingLoc?
Second, canSkipDef() skips lifetime intrinsics, but I believe those are considered clobbering by MSSA (they effectively write an undef value to the location).