conditionals

Helge Bahmann hcb@chaoticmind.net
Thu Dec 4 17:23:00 GMT 2003


Hello list,

Question about an optimization feature: I have a program that is full of
conditional variable assignments like

  if (swapped) x->a=bswap_32(a); else x->a=a;
  if (swapped) x->b=bswap_32(b); else x->b=b;
  if (swapped) x->c=bswap_32(c); else x->c=c;
  ...

(after inlining functions); I wonder if there is a way for the compiler to
make the obvious transformation into

  if (swapped) {
    x->a=bswap_32(a);
    x->b=bswap_32(b);
    ...
  } else {
    x->a=a;
    x->b=b;
    ...
  }

which is way more efficient; I tried various gcc versions (2.95, 3.2 and
3.3), even Intel icc, and neither compiler appears to be capable of doing
that (btw icc is _really_ stupid when it comes to byte-swapping)

Am I stuck with rewriting the code or is there hope that this can be
optimized by the compiler?

Best regards
-- 
Helge Bahmann <hcb@chaoticmind.net>                     /| \__
The past: Smart users in front of dumb terminals       /_|____\
                                                     _/\ |   __)
$ ./configure                                        \\ \|__/__|
checking whether build environment is sane... yes     \\/___/ |
checking for AIX... no (we already did this)            |



More information about the Gcc-help mailing list