This is an archive of the discontinued LLVM Phabricator instance.

[DeadStoreElimination] Shorten beginning of memset overwritten by later stores
ClosedPublic

Authored by junbuml on Apr 8 2016, 1:03 PM.

Diff Detail

Repository
rL LLVM

Event Timeline

junbuml updated this revision to Diff 53067.Apr 8 2016, 1:03 PM
junbuml retitled this revision from to [DeadStoreElimination] Shorten beginning of memset overwritten by later stores.
junbuml updated this object.
junbuml added a subscriber: llvm-commits.

Kindly ping

mcrosier requested changes to this revision.Apr 19 2016, 1:11 PM
mcrosier edited edge metadata.

The patch looks to be in good shape generally. I've inlined a few nits and questions/suggestions.

lib/Transforms/Scalar/DeadStoreElimination.cpp
278 ↗(On Diff #53067)

The preferred doxygen style is to drop the function name in the comments.

300 ↗(On Diff #53067)

The preferred doxygen style is to drop the function name in the comments.

303 ↗(On Diff #53067)

Once this gets committed please file a PR unless you plan on doing the follow up work.

348 ↗(On Diff #53067)

location. -> location,

429 ↗(On Diff #53067)

The other interesting case -> Another interesting case

442 ↗(On Diff #53067)

We also need -> Finally, we also need

452 ↗(On Diff #53067)

I suspect this condition 'int64_t(LaterOff + Later.Size) < int64_t(EarlierOff + Earlier.Size)' will always be true because the OverwriteComplete case will return true when LaterEnd is >= EarlyEnd.

If I am correct and the condition is true, perhaps add an assert that it's always true.

454 ↗(On Diff #53067)

I believe you dropped a comment:

// Otherwise, they don't completely overlap.
test/Transforms/DeadStoreElimination/OverwriteStoreBegin.ll
3 ↗(On Diff #53067)

4to8 -> 4to7?

16 ↗(On Diff #53067)

0to4 -> 0to3?

Should you decide to make this change, more instances below..

52 ↗(On Diff #53067)

Perhaps add a comments stating why this transformation is unsafe (i.e., we must not change the alignment of the earlier write, if I'm not mistaken).

This revision now requires changes to proceed.Apr 19 2016, 1:11 PM

Thanks Chad for the review. I will address your comments soon.

lib/Transforms/Scalar/DeadStoreElimination.cpp
303 ↗(On Diff #53067)

Yes, I will do that.

452 ↗(On Diff #53067)

Agree. If the first two condition is true and the the third condition is false, that means OverwriteComplete. As you pointed, the third condition could be an assert().

454 ↗(On Diff #53067)

Oh.. Thanks ..

test/Transforms/DeadStoreElimination/OverwriteStoreBegin.ll
16 ↗(On Diff #53067)

Thanks, I will fix them.

52 ↗(On Diff #53067)

Okay, I will comment it.

mgrang added a subscriber: mgrang.Apr 19 2016, 1:30 PM
mgrang added inline comments.
lib/Transforms/Scalar/DeadStoreElimination.cpp
341 ↗(On Diff #53067)

It's better to list the enum members alphabetically.

639 ↗(On Diff #53067)

Enclosing the RHS in parentheses makes it more readable.
bool IsOverwriteEnd = (OR == OverwriteEnd);

656 ↗(On Diff #53067)

Parentheses not really needed:

DepLoc.Size - (InstWriteOffset - DepWriteOffset) equals DepLoc.Size - InstWriteOffset - DepWriteOffset

junbuml updated this revision to Diff 54256.Apr 19 2016, 1:59 PM
junbuml edited edge metadata.

Addressed Chad's comments.

junbuml updated this revision to Diff 54263.Apr 19 2016, 2:40 PM
junbuml edited edge metadata.

Addressed Mandeep's comments. Thanks for the review.

lib/Transforms/Scalar/DeadStoreElimination.cpp
656 ↗(On Diff #53067)

DepLoc.Size - (InstWriteOffset - DepWriteOffset) is same as DepLoc.Size - InstWriteOffset + DepWriteOffset, but I think DepLoc.Size - (InstWriteOffset - DepWriteOffset) is more readable.

mcrosier accepted this revision.Apr 20 2016, 7:58 AM
mcrosier edited edge metadata.

LGTM, assuming my minor nits are addressed.

lib/Transforms/Scalar/DeadStoreElimination.cpp
289 ↗(On Diff #54263)

Any particular reason we don't support memmove? Maybe add a FIXME if it's safe to transform memmove.

303 ↗(On Diff #54263)

Supporting memcpy/memmove should...

430 ↗(On Diff #54263)

Please add a period.

658 ↗(On Diff #54263)

I agree with Jun on this one.

This revision is now accepted and ready to land.Apr 20 2016, 7:58 AM
junbuml updated this revision to Diff 54655.Apr 22 2016, 8:11 AM
junbuml edited edge metadata.

Addressed Chad's comments. Thanks for reviewing this.

This revision was automatically updated to reflect the committed changes.