public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Re: conditionals
       [not found] <Pine.LNX.4.44.0312041640010.29859-100000@lothlorien.homeli nux.net>
@ 2003-12-04 19:23 ` Eljay Love-Jensen
  2003-12-05  9:53   ` conditionals Helge Bahmann
       [not found]   ` <Pine.LNX.4.44.0312042126580.20290-100000@lothlorien.homeli nux.net>
  0 siblings, 2 replies; 4+ messages in thread
From: Eljay Love-Jensen @ 2003-12-04 19:23 UTC (permalink / raw)
  To: Helge Bahmann, gcc-help

Hi Helge,

I don't think there's an "invariant test motion" optimization, which would consolidate the conditional code block bodies for you.

That could be useful in some cases.

Especially if your test for swap/don't swap was in a macro, and you really didn't have an easy means at the code level to pull the invariant test condition out of the macro -- so consolidating the conditional bodies by hand would be even more onerous.

--Eljay


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: conditionals
  2003-12-04 19:23 ` conditionals Eljay Love-Jensen
@ 2003-12-05  9:53   ` Helge Bahmann
       [not found]   ` <Pine.LNX.4.44.0312042126580.20290-100000@lothlorien.homeli nux.net>
  1 sibling, 0 replies; 4+ messages in thread
From: Helge Bahmann @ 2003-12-05  9:53 UTC (permalink / raw)
  To: Eljay Love-Jensen; +Cc: gcc-help

Hello Eljay,

> I don't think there's an "invariant test motion" optimization, which
> would consolidate the conditional code block bodies for you.
>
> That could be useful in some cases.
>
> Especially if your test for swap/don't swap was in a macro, and you
> really didn't have an easy means at the code level to pull the invariant
> test condition out of the macro -- so consolidating the conditional
> bodies by hand would be even more onerous.

Yes, this is the case in my application (inline functions instead of
macros, though).

How hard would it be for the compiler to do that optimization?
Intuitively, it looks obvious, at least not any more complicated than cse,
but then I really don't know anything.

Thanks
-- 
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)            |


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: conditionals
       [not found]   ` <Pine.LNX.4.44.0312042126580.20290-100000@lothlorien.homeli nux.net>
@ 2003-12-05 13:01     ` Eljay Love-Jensen
  0 siblings, 0 replies; 4+ messages in thread
From: Eljay Love-Jensen @ 2003-12-05 13:01 UTC (permalink / raw)
  To: Helge Bahmann; +Cc: gcc-help

Hi Helge,

>How hard would it be for the compiler to do that optimization?

I'm not sure.  I have to defer to the GNUrus who wrote GCC.

My experience in compiler writing goes only so far as Aho's dragon book and a computer science class.

:-(
--Eljay


^ permalink raw reply	[flat|nested] 4+ messages in thread

* conditionals
@ 2003-12-04 17:23 Helge Bahmann
  0 siblings, 0 replies; 4+ messages in thread
From: Helge Bahmann @ 2003-12-04 17:23 UTC (permalink / raw)
  To: gcc-help

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)            |

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2003-12-05 13:01 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <Pine.LNX.4.44.0312041640010.29859-100000@lothlorien.homeli nux.net>
2003-12-04 19:23 ` conditionals Eljay Love-Jensen
2003-12-05  9:53   ` conditionals Helge Bahmann
     [not found]   ` <Pine.LNX.4.44.0312042126580.20290-100000@lothlorien.homeli nux.net>
2003-12-05 13:01     ` conditionals Eljay Love-Jensen
2003-12-04 17:23 conditionals Helge Bahmann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).