[llvm] [RISCV] Add TuneJumpIsExpensive (PR #191374)
Pengcheng Wang via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 16 02:45:00 PDT 2026
wangpc-pp wrote:
For the record, we have :
| | Issue Width | Performance |
|--------------|-------------|--------------------|
| SiFive P550 | 3 | Coremark (-2%) |
| XuanTie C920 | 3 | SPECINT 2006 (-1%) |
| XXX | 8 | Coremark (+1.65%) |
It seems to be beneficial when the issue width is large enough. I'd like to see more about XiangShan as the issue width is 6 or 8. @buggfg
----
> However, from a general-purpose perspective, this behavior may still be somewhat conservative.
I do agree. My point is that this may lead to different directions of compiler optimization (as what I noted in https://github.com/llvm/llvm-project/pull/74647#issuecomment-1845593084):
1. Start from a lot of branches, and turn unpredictable/unprofitable ones into selects.
2. Start from a lot of selects, and turn highly predictable/consistent ones into branches.
These two will meet in the middle but the progresses are different. We turned the direction in #74647 but we haven't enabled/tuned several optimizations (like SelectOpt(recently landed)/EearlyIfConversion/...) yet to balance branches/selects.
> Would it be possible to support both TuneJumpIsExpensive and [https://github.com/llvm/llvm-project/pull/191158](https://github.com/llvm/llvm-project/pull/191158), to enable finer-grained tuning of the trade-off between branches vs. logical-op?
I would encourage you to try some more generic ways (from high level to lower level):
1. `SimplifyCFG`: These branches are folded into selects in `llvm/lib/Transforms/Utils/SimplifyCFG.cpp:foldBranchToCommonDest`, we can convert branches into compares when the number of consecutive branches exceeds a target-specific value.
2. `SelectOptimize`: This is what https://discourse.llvm.org/t/rfc-cmov-vs-branch-optimization/6040 was talking about. We need some works here because it seems we can't handle `icmp` patterns now. I think this is most suitable place.
3. `SelectionDAGBuilder`: This is what @lukel97 was talking about. We don't need to do the conversion in an opposite aggressive way, but based on `-riscv-cbc-max-branch`.
4. `EarlyIfConversion`: We have a previous work done by @mgudim: https://github.com/llvm/llvm-project/pull/92959. We haven't enabled it yet, and there will be some works because `EarlyIfConversion` can only handle triangle and diamond CFGs.
I don't know others' thoughts. But I think, from the view of the community, we should take the best advantage of existing infrastructure. :-)
https://github.com/llvm/llvm-project/pull/191374
More information about the llvm-commits
mailing list