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]

Why the const attribute cannot work?


Title: Blank
Dear Colleagues:
    As told by Using and Porting GNU CC , functions with const attribute can be subject to common subexpression elimination and loop optimzation just as an arithmetic operator would be.But when involving the program below ,GCC cannot deal with it laconically
 
int muladd(int a,int b) __attribute__ ((const));
 
int muladd(int a, int b)
{
        return a*b+b;
}
 
main()
{
        int x = 1, y = 2, z = 3;
        int result = muladd(x,y) * (muladd(x,y) + muladd(x,y) - 1 + x * y) - x * y;
        if (result != 34) abort();
        exit(0);
}
 
it will call function muladd three times instead of only once.When I add -O2 option, the compiler with the x86 backend can recognize the common muladd function and optimize the code, but the compiler with the arm backend still cannot recognize  it and still call the function three times.
    I donnot know why the arm compiler cannot do the common muladd function elimination, and why the compilers with x86 and arm backends treat the same program differently by this question.As we know, the common expression elimination will be done in the frontend, which is independent of the target machine.
    By the way, the version I use is 2.9.5.
    Thanks for your help.

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