Page MenuHomePhabricator

[DSE] Teach the pass that atomic memory intrinsics are stores.
ClosedPublic

Authored by dneilson on Apr 11 2018, 2:09 PM.

Details

Summary

This change teaches DSE that the atomic memory intrinsics are stores
that can be eliminated, and can allow other stores to be eliminated.
This change specifically does not teach DSE that these intrinsics
can be partially eliminated (i.e. length reduced, and dest/src changed);
that will be handled in another change.

Diff Detail

Repository
rL LLVM

Event Timeline

dneilson created this revision.Apr 11 2018, 2:09 PM

I don't see any problems other than the comment inlined, but I don't know this part of code as well. Please wait for someone more familiar with it to take a look.

lib/Analysis/MemoryLocation.cpp
88 ↗(On Diff #142071)

What was the reason of renaming the parameter? Can it go as a separate NFC?

ping - any reviewers able to take a crack at this?

dmgreen added a comment.EditedApr 18 2018, 12:42 PM

Am I right in saying these are treated in the same way as unordered atomic stores are? In that they can be deleted by following non-atomic stores, even if they are "stronger" atomically? If so, this looks fine to me.

lib/Transforms/Scalar/DeadStoreElimination.cpp
868 ↗(On Diff #142071)

This one? This function does it's own special version of DSE. It's about removing stores to dead stack objects iirc.

dneilson planned changes to this revision.Apr 18 2018, 2:42 PM

Am I right in saying these are treated in the same way as unordered atomic stores are? In that they can be deleted by following non-atomic stores, even if they are "stronger" atomically? If so, this looks fine to me.

Yes, I believe that it correct -- at least that's the reasoning I've been going off of. The tests in test/Transforms/DeadStoreElimination/atomic.ll show unordered atomic stores essentially being treated the same as non-atomic stores, so if it's good there then it should be good here.

lib/Transforms/Scalar/DeadStoreElimination.cpp
868 ↗(On Diff #142071)

Good catch. Thanks!

Looks like there might not be a test for this case at all. I'll try to add one of those as well.

dneilson updated this revision to Diff 143590.Apr 23 2018, 10:05 AM
  • Update for reviewer comment.
dneilson added inline comments.Apr 23 2018, 10:08 AM
lib/Transforms/Scalar/DeadStoreElimination.cpp
868 ↗(On Diff #142071)

Made the change, but I'm having difficulty creating a test that gets to here. Calls to the memtransfer intrinsics end up getting into the conditional at line 838, above:

// If the call might load from any of our allocas, then any store above
// the call is live.
DeadStackObjects.remove_if([&](Value *I) {
  // See if the call site touches the value.
  return isRefSet(AA->getModRefInfo(CS, I, getPointerSize(I, DL, *TLI)));
});

The source argument for the intrinsic aliases the stack object(s), and this bit of code at 868 ends up having no effect.

efriedma added inline comments.Apr 23 2018, 12:00 PM
lib/Transforms/Scalar/DeadStoreElimination.cpp
868 ↗(On Diff #142071)

Yes, I agree it's impossible to get here because of the condition on line 825; an AnyMemTransferInst is also a CallSite. Please just delete this line, then.

dneilson updated this revision to Diff 143612.Apr 23 2018, 12:03 PM
  • Deleted memtransferinst case in handleEndBlock.
This revision is now accepted and ready to land.Apr 23 2018, 12:06 PM

LGTM

Thanks, Eli!

This revision was automatically updated to reflect the committed changes.