[Bug middle-end/40748] simple switch/case, if/else and arithmetics result in different code

2017-06-18 Thread glisse at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=40748

--- Comment #3 from Marc Glisse  ---
We also miss the even simpler case that should be optimized to "return n;"

int foo(int n){
switch(n){
case 0:
return 0;
case 1:
return 1;
case 2:
return 2;
case 3:
return 3;
default:
__builtin_unreachable();
}
}

llvm performs the expected optimization in both cases.

[Bug middle-end/40748] simple switch/case, if/else and arithmetics result in different code

2009-07-15 Thread rguenth at gcc dot gnu dot org


--- Comment #2 from rguenth at gcc dot gnu dot org  2009-07-15 09:34 ---
switch-conversion could try to handle this.  Generally perfect hashing during
switch expansion is another thing.


-- 

rguenth at gcc dot gnu dot org changed:

   What|Removed |Added

 Status|UNCONFIRMED |NEW
  Component|c   |middle-end
 Ever Confirmed|0   |1
   Keywords||missed-optimization
   Last reconfirmed|-00-00 00:00:00 |2009-07-15 09:34:55
   date||


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40748