We teach alias analysis that invariant.start is readonly.
This helps with GVN and memcopy optimizations that currently treat.
invariant.start as a clobber.
We need to treat this as readonly, so that DSE does not incorrectly
remove stores prior to the invariant.start
Details
Diff Detail
- Repository
- rL LLVM
Event Timeline
Changing the code to teach Alias analysis (instead of MDA) about the readonly nature of MDA. All the tests are still valid (and checks remain the same).
getModRefInfo is used by MDA, so the implications on the various passes (GVN, Memcpyopt and DSE) should be the same, it’s just that the code change will be within the same code region where other special cases for llvm.assume and guard intrinsics exist.
Making the change in alias analysis rather than MDA stemmed from the discussion in llvm-commits mailing list with dberlin and sanjoy.
[Alias Analysis] Mark invariant.start as readonly
We teach alias analysis that invariant.start is readonly.
This helps with GVN and memcopy optimizations that currently treat.
invariant.start as a clobber.
We need to treat this as readonly, so that DSE does not incorrectly
remove stores prior to the invariant.start
This initially started off as a change to teach MDA about invariant.start,
but further discussion prompted the change to alias analysis (where other such
special cases for guards and assume intrinsics exist).
lib/Analysis/BasicAliasAnalysis.cpp | ||
---|---|---|
793 ↗ | (On Diff #67159) | A more pertinent example is (I think): *ptr = 40; *ptr = 50; invariant_start(ptr) int val = *ptr; print(val); cannot be transformed to *ptr = 40; invariant_start(ptr) *ptr = 50; int val = *ptr; print(val); since the first program (always) prints 50 but the second one can be *ptr = 40; invariant_start(ptr) *ptr = 50; // This store can be ignored int val = 40; print(val); |
lib/Analysis/BasicAliasAnalysis.cpp | ||
---|---|---|
785 ↗ | (On Diff #67159) | I'm not sure if the comment is wrong. The comment intended to convey: "In other code such as MDA, instruction->MayWriteToMemory, etc, assumes and invariant.start are marked as read/write, even though they do not modify memory" However, while assume is marked as NoModRef above, we need to mark invariant.start as reading memory. It actually follows from the above 2 intrinsic comments "assume and experimental_guard" :) |
lib/Analysis/BasicAliasAnalysis.cpp | ||
---|---|---|
785 ↗ | (On Diff #67159) | I've updated the comment to: |