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: Default constructors & arrays


Gerald Pfeifer writes:
> Hmm, are you sure? On i386-unknown-freebsd2.2.6 with egcs-2.91.29 19980517
> I get the following for 
> 
>   void f() {
>       for ( int i = 0; i < 10; ++i );
>       }
> 
> compiled with gcc -c -S -O3
> 
>   	pushl %ebp
>   	movl %esp,%ebp
> 	movl $9,%eax
> 	.align 2,0x90
>   L4:
> 	decl %eax
> 	jns L4
> 	leave
> 	ret
> 
> Ah, wait a moment! With  gcc -c -S -O1 -funroll-loops (note this works
> even with -O1) indeed I get:
> 
>         pushl %ebp
>         movl %esp,%ebp
>         leave
>         ret
> 

As I said loop is removed only when the range is small and unroll can
completely unroll loop.
If you have:

   for ( int i = 0; i < 100; ++i );

this will not be removed (only shortened through unrolling).

> It seems that actually gcc.info is not completely correct, as -- with
> proper options -- egcs will indeed delete "empty" loops. 
> 
>   * Deleting "empty" loops.
> 
>      GNU CC does not delete "empty" loops because the most likely reason
>      you would put one in a program is to have a delay.  Deleting them
>      will not make real programs run any faster, so it would be
>      pointless.
>
>      It would be different if optimization of a nonempty loop could
>      produce an empty one.  But this generally can't happen.
> 

The assumption: "empty loop is in the program because somebody wanted
a delay" is wrong. If you want delay-loop declare loop variable as
volatile.

An empty loop can appear as a result of other optimizations (I am not
speaking of for(;;) loop here only): a body of the loop is invariant
to loop variable or element of an array has empty default
constructor.

Currently this mostly affects numerical computation degrading the
speed tremendously. The whole purpose of C++ is to be a better C. You
are not supposed to be penalized for something you don't do.

Having a Complex class with several constructors and an empty default
constructor results in an unusable class when speed is imperative.

The sole intention of an empty default constructor is telling the
compiler not to penalize us when constructing elements
for which we don't care about initial values, notably arrays.

> Would you be willing to accept a patch that 
>  a) removes this paragraph
> or
>  b) adds a remark about -funroll-loops?

Changing documentation won't solve that problem.

Igor


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