The following testcase reduced from Kopete is miscompiled at -O2

struct Bar { bool is() const; int status() const; };

void foobar(void);
void foobar2(void);

void Foo(const Bar& x, const Bar& y)
{
  const bool wasOffline = !x.is();
  const bool isOffline = !y.is();
  if (wasOffline || y.status() == 10)
    foobar();
  if (wasOffline != isOffline)
    foobar2();
}

.t23.mergephi:
<bb 0>:
  D.1589_3 = is (x_2);
  wasOffline_4 = !D.1589_3;
  D.1590_6 = is (y_5);
  isOffline_7 = !D.1590_6;
  if (wasOffline_4) goto <L1>; else goto <L0>;

<L0>:;
  D.1596_10 = status (y_5);
  if (D.1596_10 == 10) goto <L1>; else goto <L5>;

<L1>:;
  foobar ();

<L5>:;
  if (wasOffline_4 != isOffline_7) goto <L6>; else goto <L7>;

<L6>:;
  foobar2 ();

<L7>:;
  return;

.t24.forwprop:
<bb 0>:
  D.1589_3 = is (x_2);
  D.1590_6 = is (y_5);
  isOffline_7 = !D.1590_6;
  if (D.1589_3 == 0) goto <L1>; else goto <L0>;

<L0>:;
  D.1596_10 = status (y_5);
  if (D.1596_10 == 10) goto <L1>; else goto <L5>;

<L1>:;
  foobar ();

<L5>:;
  if (D.1589_3 != 0) goto <L6>; else goto <L7>;

<L6>:;
  foobar2 ();

<L7>:;
  return;

note that the comparison preceding foobar2() is hosed now,
we even don't use isOffline or D.1590 anymore.

-- 
           Summary: [4.0 Regression] Wrong code from forwprop
           Product: gcc
           Version: 4.0.2
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: critical
          Priority: P2
         Component: tree-optimization
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: rguenth at gcc dot gnu dot org
                CC: gcc-bugs at gcc dot gnu dot org,matz at suse dot de


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23326

Reply via email to