This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Switch case missing optimization
- From: Andrew Haley <aph at redhat dot com>
- To: David Guillen Fandos <david at davidgf dot es>, gcc-help at gcc dot gnu dot org
- Date: Sun, 3 Dec 2017 09:34:20 +0000
- Subject: Re: Switch case missing optimization
- Authentication-results: sourceware.org; auth=none
- References: <69d69082-2769-1eeb-ac96-1760effbdbeb@davidgf.es>
On 02/12/17 23:44, David Guillen Fandos wrote:
> In case I use a bunch of ifs (or a cascaded ? : sequence) it detects
> that all the resulting values are the same and therefore there's no need
> to add jumps, or even in the case where I use the last "else" to assign
> some null value it optimizes on that on subsequent code. It's
> interesting to see how switch/case is a special thing and it's never
> optimized as if it were a bunch of if/else statements.
It's important to measure stuff like this, not just look at the code.
Today's processors do an amazing job of branch prediction, and I've
found that "improving" naive-looking code doesn't always help.
Processors expect to see naive-looking code.
--
Andrew Haley
Java Platform Lead Engineer
Red Hat UK Ltd. <https://www.redhat.com>
EAC8 43EB D3EF DB98 CC77 2FAD A5CD 6035 332F A671