On 6/16/25 10:08 PM, Dongyan Chen wrote:
Hi, I've come across a question regarding the branch cost of gcc. In the link
https://gcc.godbolt.org/z/hnddevd5h, gcc fails to recognize the optimization
branch judgment, while llvm does. I eventually discovered that the value of the
branch
cost was too small. Moreover, in that link, if I add "-mbranch-cost=4" (a larger
number can also be used) for gcc, the zicond extension functions properly. So,
is
it necessary to modify the branch cost for gcc? According to the source code,
the
default mtun is rocket, which has a branch cost of 3. I think it should be set
to 4.
gcc/ChangeLog:
* config/riscv/riscv.cc: Change the branch cost.
gcc/testsuite/ChangeLog:
*
gcc.target/riscv/zicond-primitiveSemantics_compare_reg_reg_return_reg_reg.c:
New test.
So I'd be a lot more comfortable with this if someone that knows the
rocket uarch could chime in or if we had wider data on how this behaves
in general. One pico-sized benchmark isn't a great way to evaluate
something like this.
WRT a followup from Yangyu which touches on the BPI. My son is
currently putting together a tuning and scheduler model for the spacemit
x60 chip in that system under my guidance. I expect we'll start
benchmarking that work next week. We can look at the branch costing
model for that design as a part of that work.
Jeff