This is an archive of the discontinued LLVM Phabricator instance.

Correctly report modified status for LoopIdiomRecognize
ClosedPublic

Authored by serge-sans-paille on Jun 5 2020, 12:35 AM.

Diff Detail

Event Timeline

Herald added a project: Restricted Project. · View Herald TranscriptJun 5 2020, 12:35 AM
foad added a comment.Jun 5 2020, 6:34 AM

I don't particularly like all the code duplication. Is there a better way to arrange processLoopStoreOfLoopLoad?

Any chance of adding a test for this?

llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp
1109

Merge conditions to avoid the code duplication?

if (mayLoopAccessLocation(...) || 
    avoidLIRForMultiBlockLoop) {
1130–1131

Similarly, merge conditions and comment appropriately.

nikic added inline comments.Jun 5 2020, 2:13 PM
llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp
1130–1131

This is actually dead code, I've dropped it in bff94a8e2bb93267a561ca96287f570af499b090.

Introduce an helper class to aggregate the cleanup in case of rollback.

I'd prefer to conservatively return true, rather than worry about whether calling expandCodeFor and cleaning it up is actually a pure no-op in terms of use-lists etc.

serge-sans-paille marked an inline comment as done.Jun 10 2020, 11:00 PM

I'd prefer to conservatively return true, rather than worry about whether calling expandCodeFor and cleaning it up is actually a pure no-op in terms of use-lists etc.

I'm curious about the motivation behind that statement. Existing code already tries to tidy up the code (e.g. line 1084), so I feel I'm just syndicating that code in one place.

Existing code already tries to tidy up the code (e.g. line 1084), so I feel I'm just syndicating that code in one place.

I'm not against trying to clean up the code; I'm just against asserting that we successfully managed to clean up the memory representation to exactly the same form it was in before we called expandCodeFor.

I'm not against trying to clean up the code; I'm just against asserting that we successfully managed to clean up the memory representation to exactly the same form it was in before we called expandCodeFor.

https://reviews.llvm.org/D80707 should guarentee that this assertion actually holds, right?

I don't trust that analysis passes verifying themselves will catch all the issues. At best, that only proves that we didn't invalidate any analysis that happened to be live at the time LoopIdiomRecognize runs.

nikic added a comment.Jun 13 2020, 2:34 PM

@efriedma I believe @serge-sans-paille had D80916 in mind here, which provides a stronger guarantee, or at least has the potential to provide it. Of course, just returning true would be more conservative, and make little difference in practice.

llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp
1030

Rather than explicitly calling clean() in all early-return paths, maybe do this in ~ExpandedValueCleaner() automatically, and add a commit() method or so for the single success path, that clears the vector?

Use destructor to syndicate cleanup code, as suggested in the review.

serge-sans-paille marked an inline comment as done.Jun 15 2020, 6:15 AM

@efriedma I believe @serge-sans-paille had D80916 in mind here

correct :-)

nikic accepted this revision.Jun 16 2020, 12:53 PM

LG

llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp
1014

New line here seems unusual?

This revision is now accepted and ready to land.Jun 16 2020, 12:53 PM
foad added inline comments.Jun 17 2020, 1:29 AM
llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp
1066

How does this work? I thought brace initialization was only for structs with public fields (but I'm clearly not an expert). And even if it does work, wouldn't parentheses be a bit more "normal" than braces?

serge-sans-paille marked 2 inline comments as done.Jun 17 2020, 2:15 AM

Final comments addressed in the actual commit.

llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp
1066

That's a list-initialization falling back to constructor call, as described in https://en.cppreference.com/w/cpp/language/list_initialization

grep for

Otherwise, the constructors of T are considered, in two phases:

I've updated the code to use classic constructor, it's less ambiguous for the reader :-)

This revision was automatically updated to reflect the committed changes.