This is an archive of the discontinued LLVM Phabricator instance.

Fix number of args of prof branch_weights MD for SwitchInst
AbandonedPublic

Authored by yrouban on Apr 11 2019, 1:04 AM.

Details

Summary

This patch changes SwitchInst implementation to keep number of args of prof branch_weights metadata consistent across removeCase() and addCase() calls.
Appropriate code to check this consistency is added to the verifier.
Two ragreedy* tests got their broken prof metadata fixed.
Added several prof branch_weights and appropriate checks to the other 3 tests.

SimplifyCFG.cpp handles the branch weights on its own. It sets the weights when all cases are removed. So it is made to drop the metadata while removing the cases.

Note that this patch does not fix weight values when cases are changed. There will be another patch that implements prof branch_weights metadata handling for SwitchInst instruction for setting correct weights while adding or changing cases.

Diff Detail

Event Timeline

yrouban created this revision.Apr 11 2019, 1:04 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 11 2019, 1:04 AM
yrouban marked an inline comment as done.Apr 11 2019, 4:09 AM
yrouban added inline comments.
llvm/test/Transforms/SimpleLoopUnswitch/trivial-unswitch.ll
1247

As the default branch is changed it must expect !{!"branch_weights", i32 4, i32 1, i32 2} but the test passes because of a bug in SimpleLoopUnswitch. I'm fixing it and will provide one more patch. For this case I can change all weights to 1s as I did for SimpleLoopUnswitch/basictest.ll above.

yrouban updated this revision to Diff 194827.Apr 12 2019, 3:05 AM

fixed test llvm/test/Transforms/SimpleLoopUnswitch/trivial-unswitch.ll

yrouban marked an inline comment as done.Apr 12 2019, 4:11 AM
yrouban added inline comments.
llvm/lib/IR/Instructions.cpp
3843

must be uint64_t

reames requested changes to this revision.Apr 12 2019, 11:50 AM
reames added a subscriber: reames.
reames added inline comments.
llvm/test/CodeGen/AArch64/ragreedy-csr.ll
281 ↗(On Diff #194827)

Please separate and commit the test changes.

This revision now requires changes to proceed.Apr 12 2019, 11:50 AM
yrouban marked an inline comment as done.Apr 15 2019, 3:02 AM
yrouban updated this revision to Diff 195135.Apr 15 2019, 4:45 AM
  • removed 2 tests fixes into a separate patch
  • changed branch weight sum type to uint64_t
  • extracted separate method getProfBranchWeightsMD() that is used in the dependent patche
yrouban updated this revision to Diff 195307.Apr 16 2019, 12:41 AM

formatted

yrouban abandoned this revision.May 20 2019, 8:22 PM
yrouban marked an inline comment as done.

See 62122 and its children.

llvm/lib/IR/Verifier.cpp
2453

add the following from BranchProbabilityInfo

assert(Weight->getValue().getActiveBits() <= 32 && "Too many bits for uint32_t");