-funswitch-loops not effective?

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


Hi!

For the testcase


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);
}


the loop in foobar is not unswitched with -O2 -funswitch-loops,
neither for 4.0 at the tree-level, nor for 3.4 at RTL level.
Unfortunately, the dumps don't tell any reason for this, but
the assembly looks like unswitching did happen, but the pass
relied on another pass to move/remove the redundant flag
comparison?

tree dump after unswitch:

void foobar(int, const Body&) (n, body)
{
  const bool D.1599;
  struct Body * const this;
  int i;
  int i;

<bb 0>:
  if (n_3 > 0) goto <L9>; else goto <L10>;

<L10>:;
  goto <bb 5> (<L5>);

<L9>:;

  # i_1 = PHI <i_8(8), 0(6)>;
<L0>:;
  D.1599_7 = body_4->flag;
  if (D.1599_7) goto <L1>; else goto <L2>;

<L1>:;
  foo (i_1);
  goto <bb 4> (<L3>);

<L2>:;
  bar (i_1);

<L3>:;
  i_8 = i_1 + 1;
  if (n_3 > i_8) goto <L11>; else goto <L12>;

<L11>:;
  goto <bb 1> (<L0>);

<L12>:;

<L5>:;
  return;

}

Any ideas?

Thanks,
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