This is an archive of the discontinued LLVM Phabricator instance.

[DSE][MemLoc] Handle intrinsics more generically
ClosedPublic

Authored by nikic on Dec 23 2021, 12:55 AM.

Details

Summary

Remove the special casing for intrinsics in MemoryLocation::getForDest() and handle them through the general attribute based code. On the DSE side, this means that isRemovable() now needs to handle more than a hardcoded list of intrinsics. We consider everything apart from volatile accesses memory intrinsics and lifetime markers to be removable.

This allows us to perform DSE on intrinsics that DSE has not been specially been taught about, using a matrix store as an example here.

There is an interesting test change for invariant.start, but I believe that optimization is correct. It only looks a bit odd because the code is immediate UB anyway.

Diff Detail

Event Timeline

nikic created this revision.Dec 23 2021, 12:55 AM
nikic requested review of this revision.Dec 23 2021, 12:55 AM
Herald added a project: Restricted Project. · View Herald TranscriptDec 23 2021, 12:55 AM
nikic updated this revision to Diff 395996.Dec 23 2021, 12:57 AM

Further simplify code.

reames accepted this revision.Dec 23 2021, 7:13 AM
This revision is now accepted and ready to land.Dec 23 2021, 7:13 AM
fhahn accepted this revision.Dec 23 2021, 7:38 AM

LGTM, thanks!

llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
185–193

might be worth an assert here

nikic added inline comments.Dec 23 2021, 7:42 AM
llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
185–193

In some cases we call isRemovable() before getLocForWriteEx() (but still bail out if either fails). I could add an assert after reordering the calls.

fhahn added inline comments.Dec 23 2021, 1:42 PM
llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
185–193

That might be a good way to prevent accidental mis-use in future.

This revision was landed with ongoing or failed builds.Dec 24 2021, 12:31 AM
This revision was automatically updated to reflect the committed changes.
nikic added inline comments.Dec 24 2021, 1:41 AM
llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
185–193

Assert added in https://github.com/llvm/llvm-project/commit/034e66e76c6f0f76aa7c67ba4edf4eba108bcf51, though it took a few more preliminary changes than anticipated.

fhahn added inline comments.Dec 28 2021, 9:39 AM
llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
185–193

Great, thanks!