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]
Other format: [Raw text]

Re : constant propagation optimization


thank you for your answer

If I change affich() code (I put as an example an incrementation of an other variable named a),
the compiler consider c as a constant (he optimize well and remove all switch cases in inc function).

So the problem comes from the <<() calls in affich.
Is the compiler lost when he find << calls ? (cause a lot of code is generated to affich a string ) 

thank you for your help.


----- Message d'origine ----
De : Nathan Froyd <froydnj@codesourcery.com>
À : charfi asma <charfiasma@yahoo.fr>
Cc : gcc@gcc.gnu.org
Envoyé le : Jeudi, 5 Mars 2009, 17h33mn 28s
Objet?: Re: constant propagation optimization

On Thu, Mar 05, 2009 at 11:39:45AM +0000, charfi asma wrote:
> intc;

> int main()
> 
> {
> 
> Calcul ca;
> 
> c=3;
> 
> ca.affich();
> 
> ca.inc(c);
> 
> cout << "the value of c is" << c << endl;
> 
> return 0;
> 
> }
[...]
> int main()
> 
> {
> 
> Calcul ca;
> 
> ca.affich();
> 
> c=3;
> 
> ca.inc(c);
> 
> cout << "the value of c is" << c << endl;
> 
> return 0;
> 
> }
> 
> Why in the fist code, c is not considered as a constant (in spite that
> affich() does not change c)

Because GCC does not currently do the necessary analysis to know that
affich() does not change c; it therefore makes the conservative
assumption that it does.

-Nathan






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