Non-optimal code generated for H8
Segher Boessenkool
segher@kernel.crashing.org
Wed Oct 30 22:49:00 GMT 2019
On Wed, Oct 30, 2019 at 10:06:57AM +0100, David Brown wrote:
> But this also brings up another idea. Is the OP using "-Os"
> optimisation? My experience (especially with AVR, msp430, and ARM
> Cortex-M targets) is that "-Os" optimisation is often quite poor
> compared to "-O2". It can result in very significantly slower code for
> a saving of a couple of bytes, and in some cases the code can be
> significantly /bigger/ than with -O2. I don't know whether this is a
> backend issue, or a general problem with "-Os", but I no longer use or
> recommend "-Os" even for tiny embedded systems.
I have done the same for many years now, on not so tiny systems as well:
if you want compact code, you use -O2, and tune both the code and the
compiler flags manually. Some of the --params are very useful. But do
not forget about tuning the code itself, that is where the biggest gains
are possible, always. (If a better solution is hard to come up with,
try finding a better problem, instead!)
But if you have no time to waste, -Os usually give you smaller code than
-O2, even if some of the choices on the size <-> speed tradeoff are a bit
questionable (bug reports or patches welcome, of course!) And sometimes
-Os is unavoidably a bit bigger than -O2, it just sets *heuristics* after
all. But if you see this often (for some specific target?), please file
a PR for that as well.
Segher
More information about the Gcc-help
mailing list