This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
[optimization] EGCS is too pessimistic
- To: egcs at cygnus dot com
- Subject: [optimization] EGCS is too pessimistic
- From: Gabriel Dos Reis <Gabriel dot Dos-Reis at dptmaths dot ens-cachan dot fr>
- Date: 21 Dec 1998 00:32:35 +0100
Hi!
Consider (once again) the following code:
class array {
public:
array(int n) : data(new double[n]), sz(n) {}
double operator[](int i) const { return data[i]; } // certainly a read
double& operator()(int i) { return data[i]; } // a write
private:
double* const data;
const int sz;
};
const int N = 20;
int main()
{
array a(N), b(N), c(N);
for (int i=0; i<N; ++i)
a(i) = b[i] + c[i];
}
The members array::data and array::sz are *const* data members (any
construct intended to change their values results in an undefined
behaviour), so remain invariant throughout the main function,
especialy they are loop-invriants in the for-loop. Alas, EGCS
(egcs-2.92.18) is still pessimistic as ever and does generate loads
for them. Below is the (SPARC) assembly output on optimization level
-O4.
I consider these optimizations necessary for the standard library
valarray component support.
-- Gaby
.file "b.C"
gcc2_compiled.:
.section ".text"
.align 4
.global main
.type main,#function
.proc 04
main:
.LLFB1:
!#PROLOGUE# 0
save %sp, -136, %sp
.LLCFI0:
!#PROLOGUE# 1
add %fp, -24, %l2
call __builtin_vec_new, 0
mov 160, %o0
st %o0, [%fp-24]
mov 20, %l0
st %l0, [%l2+4]
add %fp, -32, %l1
call __builtin_vec_new, 0
mov 160, %o0
st %o0, [%fp-32]
add %fp, -40, %l2
st %l0, [%l1+4]
call __builtin_vec_new, 0
mov 160, %o0
st %o0, [%fp-40]
st %l0, [%l2+4]
mov 0, %o3
.LL15:
sll %o3, 3, %o2
ld [%fp-32], %o0 ! unnecessary load
ldd [%o0+%o2], %f2
ld [%fp-40], %o1 ! unnecessary load
ldd [%o1+%o2], %f6
fmovs %f2, %f4
fmovs %f3, %f5
fmovs %f6, %f2
fmovs %f7, %f3
faddd %f4, %f2, %f4
ld [%fp-24], %o0 ! unncessary load
add %o3, 1, %o3
cmp %o3, 19
ble .LL15
std %f4, [%o0+%o2]
ret
restore %g0, 0, %o0
.LLFE1:
.LLfe1:
.size main,.LLfe1-main
.section ".eh_frame",#alloc,#write
__FRAME_BEGIN__:
.uaword .LLECIE1-.LLSCIE1
.LLSCIE1:
.uaword 0x0
.byte 0x1
.byte 0x0
.byte 0x1
.byte 0x7c
.byte 0x65
.byte 0xc
.byte 0xe
.byte 0x0
.byte 0x9
.byte 0x65
.byte 0xf
.align 4
.LLECIE1:
.uaword .LLEFDE1-.LLSFDE1
.LLSFDE1:
.uaword .LLSFDE1-__FRAME_BEGIN__
.uaword .LLFB1
.uaword .LLFE1-.LLFB1
.byte 0x4
.uaword .LLCFI0-.LLFB1
.byte 0xd
.byte 0x1e
.byte 0x2d
.byte 0x9
.byte 0x65
.byte 0x1f
.align 4
.LLEFDE1:
.ident "GCC: (GNU) egcs-2.92.18 19981103 (gcc2 ss-980609 experimental)"