This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Ternary operator in loop condition
- To: law at cygnus dot com
- Subject: Re: Ternary operator in loop condition
- From: Michael Hayes <m dot hayes at elec dot canterbury dot ac dot nz>
- Date: Sun, 10 Jan 1999 22:48:27 +1300 (NZDT)
- Cc: Michael Hayes <m dot hayes at elec dot canterbury dot ac dot nz>, egcs at cygnus dot com
- References: <"13975.57349.465373.745785"@ongaonga.elec.canterbury.ac.nz><16812.915952423@hurl.cygnus.com>
Jeffrey A Law writes:
> > Looking at the unrolling problem pointed out by Richard Earnshaw I've
> > noticed that the C front end converts a loop termination condition
> > such as: 'i < (bar ? 4 : 8); i++)' into 'bar ? (i < 4) : (i < 8)'.
> >
> > Is there any good reason for doing this?
> Probably. You should track down the code which does this transformation.
Yep, once I've found my way through a maze of twisty little passages,
all alike.
> > void foo(bar)
> > int bar;
> > {
> > int i;
> >
> > for (i = 0; i < (bar ? 4 : 8); i++)
> > fred[i] = 0;
> > }
> I'd be much more interested in whether or not "bar ? 4 : 8" gets hoisted
> out of the loop since it's a loop invariant
Even without the undesirable transformation, my limited knowledge of
the loop hoisting code indicates that this still will not be hoisted.
It appears to give up once it finds a conditional branch.
Michael.