This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Ternary operator in loop condition


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.



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]