This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
gcc optimization constant propagation
- From: charfi asma <charfiasma at yahoo dot fr>
- To: gcc-help at gcc dot gnu dot org
- Date: Wed, 4 Mar 2009 09:28:37 +0000 (GMT)
- Subject: gcc optimization constant propagation
- Reply-to: charfiasma at yahoo dot fr
Hi every one,
I have a question about gcc optimization, I hope I am writing to the right list
I compiled a simple c++ program using gcc 4.0.1
#include <iostream>
using namespace std;
intc;
calss Calcul
{
public: void affich()
{
cout << "hello world" << endl;
}
public void inc (int& c)
{
switch (c)
{
case 1 : c=c+1; break;
case 2 : c=c+2; break;
case 3 : c=c+3; break;
default : c=c+0;
}
};
int main()
{
Calcul ca;
c=3;
ca.affich();
ca.inc(c);
cout << "the value of c is" << c << endl;
return 0;
}
I am interested in cpp optimisation (constant propagation)
normally, if I compile it using g++ test.cpp -O3 -fdump-tree-all, the c variable will be considered as constant (ca.inc(c); will be replaced only by c = 6; )
This kind of optimization is well done if I declare c just before ca.inc(c)): compiling the code bellow, the ca.inc(c) is replaced by c=6; (in the test1.dom1 file)
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)
Thank you very much
Asma