[fpc-pascal] why fpc do not use a known return function value
Jonas Maebe
jonas.maebe at elis.ugent.be
Tue Feb 3 16:06:40 CET 2015
On 03 Feb 2015, at 15:58, leledumbo wrote:
>> int c ;
>> int test( int p){
>> int i;
>> i = p;
>> return (i+2+c+2+c+2+c);
>> }
>> int main(){
>> c = test(128);
>> }
>
> Hmm....yes, from C perspective, there's nothing can modify c before
> it's
> used the first time (unless you inject the startup code). Therefore,
> the
> compiler is safe to assume that c is its initial global value (0)
> and is
> able to use constant propagation, with c assumed as constant to
> reduce the
> function call into a simple value.
The assembler code generated for the C program does take into account
the initial value of C:
movl _c, %eax
leal 134(%eax,%eax,2), %eax
movl %eax, _c
It could also be modified in a C program before "main" gets executed
by e.g. the initialisation code of a dynamic library.
In the end, it's not so much about constant propagation as it is about
reordering expressions to be able to fold them better.
Jonas
More information about the fpc-pascal
mailing list