-funswitch-loops not effective?

Richard Guenther rguenth@tat.physik.uni-tuebingen.de
Mon Jan 17 14:31:00 GMT 2005


On Mon, 17 Jan 2005, Richard Guenther wrote:

> void foo(int);
> void bar(int);
>
> struct Body {
>         Body(bool f) : flag(f) {}
>
>         void body(int i) const {
>                 if (flag)
>                         foo(i);
>                 else
>                         bar(i);
>         }
>
>         const bool flag;
> };
>
> void foobar(int n, const Body& body)
> {
>         for (int i=0; i<n; ++i)
>                 body.body(i);
> }

Sorry for the noise -- seems to be (again) my misunderstanding
about C++ and const.  C++ is appearantly supposed to take body.flag
possibly modified by foo() or bar().  This is also independend of
wether body.flag is public or private.  So only passing body by
value helps.

What I don't quite understand is why in the following testcase, unswitching
is happening:

void foo(int);
void bar(int);

extern const _Bool flag;

void foobar(int n)
{
        int i;
        for (i=0; i<n; ++i)
                if (flag)
                        foo(i);
                else
                        bar(i);
}

likewise, if I declare Body::flag static.

Richard.

--
Richard Guenther <richard dot guenther at uni-tuebingen dot de>
WWW: http://www.tat.physik.uni-tuebingen.de/~rguenth/



More information about the Gcc mailing list