This is the mail archive of the 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: -funswitch-loops not effective?

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)

likewise, if I declare Body::flag static.


Richard Guenther <richard dot guenther at uni-tuebingen dot de>

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