Currently, when lowering switch statement and a new basic block is built for jump table, the edge to this new block is not assigned with a correct weight. This patch collects the edge weight from all its successors and assign this sum of weights to the edge (and also the other fall-through edge). Test cases are adjusted accordingly.
Details
Diff Detail
Event Timeline
Can we add more unit test cases (with annotated profile data) to cover profile update for various switch lowering strategies?
lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp | ||
---|---|---|
1901 | Same bug occurs here too. The weight to MBB should be the sum of the ExtraWeight of all cases of 'B'. See visitBitTestCase. |
OK. I will investigate on switch lowering and try to make a test case covering all cases with profile data check.
lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp | ||
---|---|---|
1901 | You are right. I will also fix this issue in this patch. |
Update the patch by also adding forgotten edge weight when adding bit test header for lowering switch statement.
This looks fine to me in general, but other reviewers or Hans may need to take a look.
(The additional test cases can be added as a follow up).
This looks fine to me, but it would be really nice to get tests here.
lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp | ||
---|---|---|
1901 | Does it get the DefaultWeight right here? (Not a criticism, just wondering if this ever worked.) | |
8018 | I think the sum of all the branch weights on a branch (in this case a SwitchInst) will not overflow an uint32_t. Since we're adding up weights from the same switch it should be safe to use uint32_t for JumpWeight and skip the ScaleWeights below. |
Change the type of weight from uint64_t to uint32_t as there won't be overflow in calculation.
Add a test case that checks if the edge weight to the jump table is correct.
Hi Hans
Could you please take a look at this patch and see if it is ok to be
checked in? Thank you!
Cong
thanks,
Cong
Yes, lgtm. Sorry for the delay.
test/CodeGen/X86/switch-jump-table.ll | ||
---|---|---|
58 | This isn't really checking the probabilities though, but the block placement. Maybe that's the best we can do? :-/ Maybe use a more descriptive prefix than CHECK2? CHECK-PLACEMENT? |
test/CodeGen/X86/switch-jump-table.ll | ||
---|---|---|
58 | As this fix is for lowering IR to MC so I think the best pass that we should indicate here is expand-isel-pseudos. I have updated it. I also changed CHECK2 into CHECK-JT-WEIGHT to make it more descriptive. Thanks! |
Same bug occurs here too. The weight to MBB should be the sum of the ExtraWeight of all cases of 'B'. See visitBitTestCase.