llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.11k stars 11.61k forks source link

Conditionalize code gen based on hotness/coldness #35752

Open davezarzycki opened 6 years ago

davezarzycki commented 6 years ago
Bugzilla Link 36404
Version trunk
OS All
CC @hiraditya,@RKSimon,@rotateright

Extended Description

This bug is a followup to discussion in: https://reviews.llvm.org/D43201

It would be great if the compiler could conditionalize code gen based on the hot/cold nature of functions and/or basic blocks. Anecdotally speaking (from my experience at Apple), improving overall code density tends to improve overall system performance. That being said, microbenchmarks sometimes suffer.

It would be great if LLVM could optimize for "reasonable size" (i.e. not micro-coded; a.k.a. -Os not -Oz) by default and then switch to throughput optimized code gen when evidence suggests that a "hot path" exists. At best, evidence can include profile guided optimization and explicit source attributes; and at worst simple heuristics.

davezarzycki commented 4 years ago

That would certainly help. That being said, lots of projects don't profile for various reasons.

Personally, I think the best bang-for-buck solution is to have two default optimization levels: one for obvious loops and one for everything else. This would also work well with things like code alignment (where loops are aligned but everything else is unaligned for density reasons).

hiraditya commented 4 years ago

Do you think Hot cold splitting maybe helpful in this case?

https://reviews.llvm.org/D50658