http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57071
--- Comment #5 from Tobias Burnus <burnus at gcc dot gnu.org> 2013-04-26 07:26:31 UTC --- (In reply to comment #3) > 1 - ISHFT(IAND(K,1),1) For the real version Jakub suspects that (k & 1) ? -1.0 : 1.0 is faster than the mod/convert to float/subtraction or the and/shift/convert to float/substraction, cf. PR 57073. (In reply to comment #4) h> note that in the case of k being a loop index, there will be pretty good range > infomation (e.g. k>=0) But that requires a complicated flow analysis - you have to track where the exponent gets set etc. And you only gain little compared to the k&1?-1.:1. or 1.0-((k&1)<<1) algorithm - they might even be faster and are more general. It is also not really clear to me whether the proposal of comment 4 has a benefit. I think the biggest advantage is to replace a function call by inline code; that allows more middle-end optimizations as it is inline - and as the inlined code is small, it should always be a win in code size (and, of course, performance). (For completeness: The original algorithm works if one replaces "mod" by "modulo".)