- Merge cases are added for simplify-cfg {sink,hoist}, based on https://gcc.godbolt.org/z/avGvc38W7 and https://gcc.godbolt.org/z/dbWbjGhaE
- When one instruction folds the others in, do not update branch_weights with sum (see test/Transforms/GVN/calls-readonly.ll)
Details
Diff Detail
Event Timeline
llvm/test/Transforms/SimplifyCFG/merge-direct-call-branch-weights-in-hoist.ll | ||
---|---|---|
2 | You need --check-globals to check the resulting metadata. Also, it should be possible to reduce these tests to basically an if/else with a call each. |
llvm/include/llvm/IR/Metadata.h | ||
---|---|---|
1322 | Have an one line summary of what the interface does here. Move the detailed documentation to the function definition. | |
llvm/lib/IR/Metadata.cpp | ||
1075 | Why not naming it 'mergeDirectCallProfMetadata'? Even if there is a need to merge indirect call profiles, the implementation will be quite different and may require a different method for it. | |
1078 | Combine these two into if (! (A&&B)) return; | |
1101 | how about == 2? | |
1116 | why is the check needed? |
llvm/lib/IR/Metadata.cpp | ||
---|---|---|
1075 |
This is true. Here either the caller 'combineMetadata' or callee ('getMergedProfMetadata' or 'mergeDirectCallProfMetadata') needs to look at 'AInstr' or 'BInstr' to decide if it's the implemented case, and it looks cleaner (in the caller) by putting details in the callee 'getMergedProfMetadata' Added a private method 'mergeDirectCallProfMetadata' to make future expansions easier. | |
1101 | '== 2' works for 'callinstr' with 'branch_weights' (e.g., after seeing AProfName.equals("branch_weights") && BProfName.equals("branch_weights")) -> yet !prof for direct callsites might be expanded in the future (like invoke prof could have both branch weights and value profiles) so here make assertions closer what LLVM verifier already verifies. | |
1116 | Changed it to assert since verifier already has Check(mdconst::dyn_extract<ConstantInt>(MDO), "!prof brunch_weights operand is not a const int"); | |
llvm/test/Transforms/SimplifyCFG/merge-direct-call-branch-weights-in-hoist.ll | ||
2 | thanks! Reduced the test case and added '-check-globals' |
llvm/lib/Transforms/Utils/Local.cpp | ||
---|---|---|
2721 | This should probably be behind a DoesKMove check? If we're CSEing with a dominating call, it doesn't make sense to add the branch weights, as the second call is being removed. I'd suggest adding a test with a readonly/nounwind/willreturn call being GVNed to cover that case. |
llvm/lib/Transforms/Utils/Local.cpp | ||
---|---|---|
2721 | good catch. |
plan changes as suggested.
llvm/lib/Transforms/Utils/Local.cpp | ||
---|---|---|
2721 | thanks for the catch! Just to confirm I'm getting the point (not particular to a specific pass yet), in https://gcc.godbolt.org/z/nGa6YqWdP, two calls to 'func1' in line 11 and line14 should keep one branch weight (rather than the sum of two). So that is the case when unifying (not merge) is correct. |
llvm/lib/Transforms/Utils/Local.cpp | ||
---|---|---|
2721 | Yeah, that's the case I had in mind. After the transform only the first call will be executed, so it would make sense to me to only keep its call count. |
gate the sum of branch weights by DoesKMove and add test case when one callsite folds away (GVN'ed the other)
llvm/lib/Transforms/Utils/Local.cpp | ||
---|---|---|
2721 | https://gcc.godbolt.org/z/9cnd3qEce is a test case when EarlyCSE CSE'ed call to 'func1', while turns out the current implementation doesn't invoke merge-metadata around where calls are CSE'ed (probably goes to a follow-up patch) Modified existing test case in GVN. |
Have an one line summary of what the interface does here. Move the detailed documentation to the function definition.