top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration Why to Join

Facebook Login
Site Registration
Print Preview

Does GCC perform profile-guided switch case reordering and balancing?

+2 votes

I'm working on a program where a few switch statements end up being hotspots. Some manual experimentation shows that rearranging switch cases so that more commonly executed ones appear together helps, as does checking for the most common case separately. The downside is that it makes the code uglier. Can GCC perform these kinds of optimizations as part of PGO, and how good is it at it?

posted Jul 21, 2013 by anonymous

Looking for an answer?  Promote on:
Facebook Share Button Twitter Share Button Google+ Share Button LinkedIn Share Button Multiple Social Share Button

Similar Questions
+1 vote
  1. GCC is available in several variations (SJLJ, DW2, SEH). When compiling plain C code (therefore either assuming or explicitly specifying -fno-exceptions), does it make any difference which GCC variation is used?

  2. Further I assume, that if my plain C code was to link to a C++ library which may throw exceptions, then it would matter which GCC variation I use. In that case, I should use the GCC variation that matches with the C++ code exception flavour, I should enable -fexceptions when compiling my plain C code, and the exceptions could
    then propagate over the C code?

0 votes

I've noticed the difference in gcc and llvm behaviour with the following code:

$ cat test.c

int main()
 for(int i = 0;; ({break;}))
 printf("Hello, worldn");

$ clang test.c -pedantic &; ({break;}))
1 warning generated.
Hello, world

$ gcc test.c -std=gnu11 -pedantic &; ({break;}))
test.c:5:21: warning: ISO C forbids braced-groups within expressions [-Wpedantic]
 for(int i = 0;; ({break;}))

So, llvm thinks that this is GNU extension (seems like it really is), but compiles it, and gcc does not, even if the standard is specified as gnu11. Is it a bug?

0 votes

Can I use gcc as well as java compiler on a single desktop?

+1 vote

I don't really understand this option. I enabled it but it warns for essentially all of my classes which have any virtual methods. For
example if I have Foo.h:

 class Foo {
 virtual bool bar();

then Foo.cpp which implements Foo. And then in another header somewhere else I inherit from Foo and implement bar() differently (as a virtual function). However when GCC compiles Foo.cpp it can't see the other header, so I guess it assumes no one inherits from Foo and suggests it should be marked final:

Declaring type 'class Foo' final would enable devirtualization of N calls

I mean sure, it would, but that would defeat the entire point (as I understand it).

I don't really understand how/where this option is meant to be used.
Ditto for -Wsuggest-final-methods.

Useful Links with Similar Problem
Contact Us
+91 9880187415
#470/147, 3rd Floor, 5th Main,
HSR Layout Sector 7,
Bangalore - 560102,
Karnataka INDIA.