This is an archive of the discontinued LLVM Phabricator instance.

[ArgPromotion] Change the condition to check the promotion limit
ClosedPublic

Authored by psamolysov on Apr 21 2022, 7:51 AM.

Details

Summary

The condition should be 'ArgParts.size() > MaxElements', so that if we
have exactly 3 elements in the 'ArgParts' vector, the promotion should
be allowed because the 'MaxElement' threshold is not exceeded yet.

The default value for 'MaxElement' has been decreased to 2 in order
to avoid an actual change in argument promoting behavior. However,
this changes byval argument transformation behavior by allowing
adding not more than 2 arguments to the function instead of 3 allowed
before.

Diff Detail

Event Timeline

psamolysov created this revision.Apr 21 2022, 7:51 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 21 2022, 7:51 AM
psamolysov requested review of this revision.Apr 21 2022, 7:51 AM
aeubanks accepted this revision.Apr 21 2022, 11:57 AM

looks good

llvm/test/Transforms/ArgumentPromotion/max-elements-limit.ll
2

-o - should be unnecessary

53

remove unrelated IR (and things like dso_local above)

This revision is now accepted and ready to land.Apr 21 2022, 11:57 AM
psamolysov marked 2 inline comments as done.

@aeubanks Thank you for the comments. I've applied your suggestions.

Colleagues, could you help me with the landing, please?

nikic added a comment.Apr 22 2022, 3:00 AM

I think we also need to adjust MaxElements by one to avoid an actual change in behavior.

@nikic Thank you, good idea. I've adjusted the default value to 2. The LIT test was also updated to cover both cases: if there are 2 parts, the arguments can be promoted but if there are 3 parts, they cannot.

psamolysov edited the summary of this revision. (Show Details)

Adjust the default value for MaxElements.

Rebasing to main, the previous patch cannot be applied by some unknown reasons.

Fix the issue with patch applying.

aeubanks added inline comments.Apr 25 2022, 9:31 AM
llvm/include/llvm/Transforms/IPO/ArgumentPromotion.h
28 ↗(On Diff #424503)

MaxElements is also used elsewhere (handling byval args) besides the one place below.

I think making the two uses consistent makes sense and should be ok, but that should be noted in the description (this doesn't preserve existing behavior as currently stated). if somebody complains about this regressing anything, we can split MaxElement into two separate parameters

psamolysov edited the summary of this revision. (Show Details)Apr 26 2022, 5:07 AM
psamolysov marked an inline comment as done.
psamolysov added inline comments.
llvm/include/llvm/Transforms/IPO/ArgumentPromotion.h
28 ↗(On Diff #424503)

@aeubanks Thank you for the comment. I've changed the description to make it more concrete, the changing of the default MaxElement value preserves existing behavior for argument promoting but changes behavior for byval argument transformation.

psamolysov marked an inline comment as done.Apr 26 2022, 5:08 AM

If the changes make sense, could you land it, please?

Rebase to main