This is an archive of the discontinued LLVM Phabricator instance.

[argprom] Assessing impact of magic value MaxElements promoted on compiler performance
Needs ReviewPublic

Authored by teamiceberg on Jul 14 2020, 6:51 PM.

Details

Reviewers
jdoerfert
Summary

Our initial hypothesis is that changes to the magic value of (unsigned) MaxElements variable in ArgumentPromotion.cpp/ArgumentPromotion.h file can lead to changes in both compile time and run time compiler performance. To assess such changes, we extern declare a global variable (unsigned MaxElemsToPromote) in the IPO.h header file (default defined to 3 in ArgumentPromotion.h). Then, we supply different values for this global variable through an OPT command line flag (-argpromotion-max-elements-to-promote) bound to this global variable via the cl::opt interface. Initial analysis of compiler performance using the built-in test suite demonstrate some significant changes in compile time as well as run time, including beneficial changes(reductions in CT/RT) for some test cases.We are in the process of validating if these changes are real or just noise induced by other means. More experiments and sample runs need to be run, to be sure.
However, we are setting up this initial patch as a way to learn how to setup a pipeline to enable the use of global variables to simulate magic values. Also, we are designing a LIT test in llvm/tests folder to ensure that we submit a patch that demonstrates that the OPT flag works.
Regression Test Setup: /llvm/test/Transforms/ArgumentPromotion has 1 test written by me (fourmember-struct-promote.ll) which demonstrates the flag works successfully.
Regression Test success criteria: For aggregate arguments, such as structs, by design only a maximum of 3 members are promoted. However by introducing a custom OPT flag, we can set this number to different values to promote any number of an aggregate's arguments. For instance, the regression test file "fourmember-struct-promote.ll" has a four member struct passed by reference to a simple callee that sums the values of the members. The flag '-argpromotion-max-elements-to-promote' value has to be 0 or 4 (or higher) for all 4 members in the struct to be promoted. '0' defaults to 'always promote'. Supplying a value less than the number of members in the aggregate (in this case 4) halts promotion. The regression tests are designed to PASS when the FILECHECK tool pattern matches against an output that reflects all members have been promoted to "by value" for -argpromotion-max-elements-to-promote=[0 , 3, INT_MAX] cases respectively.

RESULTS:
fourmember-struct-promote.ll test PASSES according to success criteria defined above.
Therefore, we conclude that the --argpromotion-max-elements-to-promote user flag works correctly.

Now that we have this flag working correctly, users can test out the impact of argument promotion of elements of aggregates on compile time and run time performance.

Diff Detail

Event Timeline

teamiceberg created this revision.Jul 14 2020, 6:51 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 14 2020, 6:51 PM
jdoerfert added inline comments.Jul 14 2020, 7:02 PM
llvm/include/llvm/Transforms/IPO/ArgumentPromotion.h
19

The comment describes something unrelated.
Please rename the variable according to the naming convention.
A static variable definition in a header is problematic if the header is included more than once. Please use an extern variable declaration here and put the definition in the cpp file.

llvm/lib/Transforms/IPO/ArgumentPromotion.cpp
94

use a more expressive command line option name, e.g., argpromotion-max-argument-increase-per-promotion. Please update the description to describe what this actually controls. No need for value_desc.

1122

Please do not simply ignore the argument MaxElements that is passed here by the user of this function. If you want to modify the default for the old pass manager, which is using this function, please update the call site where there is a 3.

llvm/test/Transforms/ArgumentPromotion/fourmember-struct-promote-DEFAULT.ll
91

No need for the metadata and attributes at the end of this file, please remove.

llvm/test/Transforms/ArgumentPromotion/fourmember-struct-promote-INTMAX.ll
1

Please merge all three test files into one with 3 RUN lines and different check labels.

jdoerfert added inline comments.Jul 14 2020, 7:38 PM
llvm/test/Transforms/ArgumentPromotion/fourmember-struct-promote-DEFAULT.ll
1

run mem2reg on the file *before* making it a test, not here.

teamiceberg marked an inline comment as done.
This comment was removed by teamiceberg.

Diff Update V1 - All changes requested except consolidation of 3 RUNS in one file

teamiceberg marked 5 inline comments as done.

Diff Update V2 - Consolidated 3 RUNS in one test file. Individual files deleted.

teamiceberg edited the summary of this revision. (Show Details)Jul 15 2020, 2:54 PM
teamiceberg marked an inline comment as done.

Re-basing against LLVM master

jdoerfert added inline comments.Jul 16 2020, 6:11 PM
llvm/include/llvm/Transforms/IPO.h
34

No need to explain it is a global variable. Explain what the meaning is, e.g., what does the number indicate.

llvm/lib/Transforms/IPO/ArgumentPromotion.cpp
97

The comment is above is not necessary. The first sentence of the description is sufficient. The option should be hidden, compare other command line options please. The name of the variable is not proper.

101

Explain the meaning not where an extern definition is and that the value is by default three.

1122

Where is the change in the pass manager?

All change requirements comments except Pass Manager change requirements addressed.I need more information to address Pass Manager CR.

teamiceberg marked an inline comment as done.

Written text changes to patch's subject message. No source code changes.