public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/34768]  New: [4.1/4.2/4.3 Regression] Wrong code with conditional function invocation
@ 2008-01-13 14:01 rguenth at gcc dot gnu dot org
  2008-01-13 14:04 ` [Bug middle-end/34768] " rguenth at gcc dot gnu dot org
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2008-01-13 14:01 UTC (permalink / raw)
  To: gcc-bugs

int x;

void __attribute__((noinline)) foo (void)
{
  x = -x;
}
void __attribute__((const,noinline)) bar (void)
{
}

int __attribute__((noinline))
test (int c)
{
  int tmp = x;
  (c ? foo : bar) ();
  return tmp + x;
}

extern void abort (void);
int main()
{
  x = 1;
  if (test (1) != 0)
    abort ();
  return 0;
}

creates wrong code because the side-effect of the call to foo() is not
accounted for.

Since the merge of tree-ssa already gimplification removes the function call.
Thus, the above fails with -O0.


If you modify the testcase to use the return-value, you see that wrong
alias information is created because we appearantly use the const attribute
for the indirect call.

int x;

int __attribute__((noinline)) foo (void)
{
  x = -x;
  return 0;
}
int __attribute__((const,noinline)) bar (void)
{
  return 0;
}

int __attribute__((noinline))
test (int c)
{
  int tmp = x;
  int res = (c ? foo : bar) ();
  return tmp + x + res;
}

extern void abort (void);
int main()
{
  x = 1;
  if (test (1) != 0)
    abort ();
  return 0;
}

alias produced is:

test (c)
{
  int res;
  int tmp;
  int D.1207;
  int x.3;
  int D.1205;
  int (*<T240>) (void) iftmp.2;

<bb 2>:
  # VUSE <x_11(D)>
  tmp_2 = x;
  if (c_3(D) != 0)
    goto <bb 4>;
  else
    goto <bb 3>;

<bb 3>:

<bb 4>:
  # iftmp.2_1 = PHI <foo(2), bar(3)>
  res_6 = iftmp.2_1 ();
  # VUSE <x_11(D)>
  x.3_7 = x;
  D.1207_8 = tmp_2 + x.3_7;
  D.1205_9 = D.1207_8 + res_6;
  return D.1205_9;

}

and we happily CSE the load from x.  This testcase requires -O to fail.


-- 
           Summary: [4.1/4.2/4.3 Regression] Wrong code with conditional
                    function invocation
           Product: gcc
           Version: 4.3.0
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: normal
          Priority: P3
         Component: middle-end
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: rguenth at gcc dot gnu dot org


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


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2008-07-04 16:18 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-01-13 14:01 [Bug middle-end/34768] New: [4.1/4.2/4.3 Regression] Wrong code with conditional function invocation rguenth at gcc dot gnu dot org
2008-01-13 14:04 ` [Bug middle-end/34768] " rguenth at gcc dot gnu dot org
2008-01-13 14:36 ` [Bug c/34768] " rguenth at gcc dot gnu dot org
2008-01-13 14:36 ` rguenth at gcc dot gnu dot org
2008-01-13 18:02 ` pinskia at gcc dot gnu dot org
2008-01-13 18:34 ` rguenth at gcc dot gnu dot org
2008-01-16 10:17 ` rguenth at gcc dot gnu dot org
2008-01-16 10:29 ` [Bug c/34768] [4.1/4.2 " rguenth at gcc dot gnu dot org
2008-01-22 14:48 ` rguenth at gcc dot gnu dot org
2008-01-22 14:57 ` [Bug c/34768] [4.1 " rguenth at gcc dot gnu dot org
2008-07-04 16:18 ` jsm28 at gcc dot gnu dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).