[llvm] [RISCV] Add getJumpConditionMergingParams to support branch condition merging (PR #206897)
Pengcheng Wang via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 2 05:16:46 PDT 2026
wangpc-pp wrote:
> should we use MispredictPenalty in some way to make a slightly smarter decision?
Done but very naive.
In RISC-V, we have subtargets that have very different penalties (3 for Rocket/SCR1, up to 14 for Ascalon). A deep OoO pipeline benefits far more from killing a branch than a small in-order core, so a static `BaseCost = 2` under-serves both ends.
But I think we shouldn't use the raw penalty as the budget. A branch only costs the penalty when it is mispredicted. Merging always pays the RHS cost, but only sometimes saves the penalty. Using the raw value like 14 directly would over-merge aggressively. I have investigated other uses of `MispredictPenalty`: `SelectOptimize` multiplies by a ~25% mispredict rate, X86's `CmovConversion` divides by 4. So maybe something like `MispredictPenalty / 4 (or * rate)` is the honest quantity.
@lenary As for these cores that really care about code size, they usually have a small pipeline (which means a small `MispredictPenalty`). So they will tend to not merge the branches. Hopefully this addresses your concern. :-)
https://github.com/llvm/llvm-project/pull/206897
More information about the llvm-commits
mailing list