[SimplifyCFG] 'Fold branch to common dest': don't overestimate the cost
authorRoman Lebedev <lebedev.ri@gmail.com>
Tue, 23 Mar 2021 15:22:30 +0000 (18:22 +0300)
committerRoman Lebedev <lebedev.ri@gmail.com>
Tue, 23 Mar 2021 15:30:26 +0000 (18:30 +0300)
commitb5822026dd727e23a6ed6270f9844e0021141607
treeeeac03d5731f503ca15f49071c6b05cfde12e899
parenta866f72eb2b52b46799e5c64b1b25df4f6fa91e7
[SimplifyCFG] 'Fold branch to common dest': don't overestimate the cost

`FoldBranchToCommonDest()` has a certain budget (`-bonus-inst-threshold=`)
for bonus instruction duplication. And currently it calculates the cost
as-if it will actually duplicate into each predecessor.

But ignoring the budget, it won't always duplicate into each predecessor,
there are some correctness and profitability checks.
So when calculating the cost, we should first check into which blocks
will we *actually* duplicate, and only then use that block count
to do budgeting.
llvm/lib/Transforms/Utils/SimplifyCFG.cpp
llvm/test/Transforms/SimplifyCFG/fold-branch-to-common-dest-two-preds-cost.ll