public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/43784]  New: [4.6 Regression] -Os -fkeep-inline-functions causes FAIL: gcc.c-torture/execute/builtins/pr22237.c execution
@ 2010-04-18 16:25 zsojka at seznam dot cz
  2010-04-18 16:26 ` [Bug tree-optimization/43784] " zsojka at seznam dot cz
                   ` (11 more replies)
  0 siblings, 12 replies; 13+ messages in thread
From: zsojka at seznam dot cz @ 2010-04-18 16:25 UTC (permalink / raw)
  To: gcc-bugs

Tested revisions:
r158486 - fail
r158225 - OK
4.5 r158131 - OK
4.4 r158133 - OK

Compiler output:
$ /mnt/svn/gcc-trunk/binary-158486-lto-fortran/bin/gcc -Os
-fkeep-inline-functions testcase.c && ./a.out
Aborted


-- 
           Summary: [4.6 Regression] -Os -fkeep-inline-functions causes
                    FAIL: gcc.c-torture/execute/builtins/pr22237.c execution
           Product: gcc
           Version: 4.6.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: zsojka at seznam dot cz
  GCC host triplet: x86_64-pc-linux-gnu
GCC target triplet: x86_64-pc-linux-gnu


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


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

* [Bug tree-optimization/43784] [4.6 Regression] -Os -fkeep-inline-functions causes FAIL: gcc.c-torture/execute/builtins/pr22237.c execution
  2010-04-18 16:25 [Bug tree-optimization/43784] New: [4.6 Regression] -Os -fkeep-inline-functions causes FAIL: gcc.c-torture/execute/builtins/pr22237.c execution zsojka at seznam dot cz
@ 2010-04-18 16:26 ` zsojka at seznam dot cz
  2010-04-18 18:17 ` rguenth at gcc dot gnu dot org
                   ` (10 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: zsojka at seznam dot cz @ 2010-04-18 16:26 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from zsojka at seznam dot cz  2010-04-18 16:26 -------
Created an attachment (id=20409)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=20409&action=view)
reduced testcase (from gcc.c-torture/execute/builtins/pr22237.c)

Command line:
gcc -Os -fkeep-inline-functions pr43784.c && ./a.out


-- 


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


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

* [Bug tree-optimization/43784] [4.6 Regression] -Os -fkeep-inline-functions causes FAIL: gcc.c-torture/execute/builtins/pr22237.c execution
  2010-04-18 16:25 [Bug tree-optimization/43784] New: [4.6 Regression] -Os -fkeep-inline-functions causes FAIL: gcc.c-torture/execute/builtins/pr22237.c execution zsojka at seznam dot cz
  2010-04-18 16:26 ` [Bug tree-optimization/43784] " zsojka at seznam dot cz
@ 2010-04-18 18:17 ` rguenth at gcc dot gnu dot org
  2010-05-22 17:12 ` zsojka at seznam dot cz
                   ` (9 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2010-04-18 18:17 UTC (permalink / raw)
  To: gcc-bugs



-- 

rguenth at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |4.6.0


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


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

* [Bug tree-optimization/43784] [4.6 Regression] -Os -fkeep-inline-functions causes FAIL: gcc.c-torture/execute/builtins/pr22237.c execution
  2010-04-18 16:25 [Bug tree-optimization/43784] New: [4.6 Regression] -Os -fkeep-inline-functions causes FAIL: gcc.c-torture/execute/builtins/pr22237.c execution zsojka at seznam dot cz
  2010-04-18 16:26 ` [Bug tree-optimization/43784] " zsojka at seznam dot cz
  2010-04-18 18:17 ` rguenth at gcc dot gnu dot org
@ 2010-05-22 17:12 ` zsojka at seznam dot cz
  2010-05-22 17:33 ` zsojka at seznam dot cz
                   ` (8 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: zsojka at seznam dot cz @ 2010-05-22 17:12 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from zsojka at seznam dot cz  2010-05-22 17:11 -------
Fails with -m32 too (as of r159696)
-fno-ipa-profile doesn't help (that flag is new in r158969 compared to r158095)

The problem is that temporary struct isn't created, and direct copy *q = *p is
done. (rp is called with output parameter (rdi) == q, not a pointer to
temporary data on stack)

Furthermore, qp() isn't emitted in the object file (in neither r158095 or
r158969), even though -fkeep-inline-functions was specified. (I am not sure
this is a bug)


-- 


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


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

* [Bug tree-optimization/43784] [4.6 Regression] -Os -fkeep-inline-functions causes FAIL: gcc.c-torture/execute/builtins/pr22237.c execution
  2010-04-18 16:25 [Bug tree-optimization/43784] New: [4.6 Regression] -Os -fkeep-inline-functions causes FAIL: gcc.c-torture/execute/builtins/pr22237.c execution zsojka at seznam dot cz
                   ` (2 preceding siblings ...)
  2010-05-22 17:12 ` zsojka at seznam dot cz
@ 2010-05-22 17:33 ` zsojka at seznam dot cz
  2010-06-11 21:03 ` zsojka at seznam dot cz
                   ` (7 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: zsojka at seznam dot cz @ 2010-05-22 17:33 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from zsojka at seznam dot cz  2010-05-22 17:32 -------
-fno-ipa-pure-const prevents the problem (the code is the same as when compiled
by r158095)


-- 


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


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

* [Bug tree-optimization/43784] [4.6 Regression] -Os -fkeep-inline-functions causes FAIL: gcc.c-torture/execute/builtins/pr22237.c execution
  2010-04-18 16:25 [Bug tree-optimization/43784] New: [4.6 Regression] -Os -fkeep-inline-functions causes FAIL: gcc.c-torture/execute/builtins/pr22237.c execution zsojka at seznam dot cz
                   ` (3 preceding siblings ...)
  2010-05-22 17:33 ` zsojka at seznam dot cz
@ 2010-06-11 21:03 ` zsojka at seznam dot cz
  2010-07-23 11:20 ` rguenth at gcc dot gnu dot org
                   ` (6 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: zsojka at seznam dot cz @ 2010-06-11 21:03 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from zsojka at seznam dot cz  2010-06-11 21:02 -------
When rp() is declared with __attribute__((pure)), it fails even with
-fno-ipa-pure-const. (still fails in r160527)
I don't know if this is a bug or if this behaviour is fine according to
standard.


-- 


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


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

* [Bug tree-optimization/43784] [4.6 Regression] -Os -fkeep-inline-functions causes FAIL: gcc.c-torture/execute/builtins/pr22237.c execution
  2010-04-18 16:25 [Bug tree-optimization/43784] New: [4.6 Regression] -Os -fkeep-inline-functions causes FAIL: gcc.c-torture/execute/builtins/pr22237.c execution zsojka at seznam dot cz
                   ` (4 preceding siblings ...)
  2010-06-11 21:03 ` zsojka at seznam dot cz
@ 2010-07-23 11:20 ` rguenth at gcc dot gnu dot org
  2010-07-23 11:36 ` rguenth at gcc dot gnu dot org
                   ` (5 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2010-07-23 11:20 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from rguenth at gcc dot gnu dot org  2010-07-23 11:20 -------
Confirmed.  But I think this might trigger undefined behavior according to
the C standard as you are doing

  v.e.b = v.d.b;

which has overlapping lhs/rhs.  And we end up with

rp:
.LFB0:
        .cfi_startproc
        movq    %rdi, %rax
        movl    $v, %esi
        movl    $64, %ecx
        rep movsl
        ret
        .cfi_endproc

compared to 4.5 we end up with return slot optimization for the call to rp().

Testcase that also reproduces with -O[123]:

struct s {
  unsigned char a[256];
};
union u {
  struct { struct s b; int c; } d;
  struct { int c; struct s b; } e;
};

static union u v;
static struct s *p = &v.d.b;
static struct s *q = &v.e.b;

static struct s __attribute__((noinline)) rp(void)
{
  return *p;
}

static void qp(void)
{
  *q = rp();
}

int main()
{
  int i;
  for (i = 0; i < 256; i++)
    p->a[i] = i;
  qp();
  for (i = 0; i < 256; i++)
    if (q->a[i] != i)
      __builtin_abort();
  return 0;
}


-- 

rguenth at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|0                           |1
           Priority|P3                          |P1
   Last reconfirmed|0000-00-00 00:00:00         |2010-07-23 11:20:14
               date|                            |


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


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

* [Bug tree-optimization/43784] [4.6 Regression] -Os -fkeep-inline-functions causes FAIL: gcc.c-torture/execute/builtins/pr22237.c execution
  2010-04-18 16:25 [Bug tree-optimization/43784] New: [4.6 Regression] -Os -fkeep-inline-functions causes FAIL: gcc.c-torture/execute/builtins/pr22237.c execution zsojka at seznam dot cz
                   ` (5 preceding siblings ...)
  2010-07-23 11:20 ` rguenth at gcc dot gnu dot org
@ 2010-07-23 11:36 ` rguenth at gcc dot gnu dot org
  2010-07-23 11:40 ` rguenth at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2010-07-23 11:36 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from rguenth at gcc dot gnu dot org  2010-07-23 11:36 -------
We still need to deal with it in the middle-end.  I have a patch.


-- 

rguenth at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|unassigned at gcc dot gnu   |rguenth at gcc dot gnu dot
                   |dot org                     |org
             Status|NEW                         |ASSIGNED
   Last reconfirmed|2010-07-23 11:20:14         |2010-07-23 11:36:24
               date|                            |


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


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

* [Bug tree-optimization/43784] [4.6 Regression] -Os -fkeep-inline-functions causes FAIL: gcc.c-torture/execute/builtins/pr22237.c execution
  2010-04-18 16:25 [Bug tree-optimization/43784] New: [4.6 Regression] -Os -fkeep-inline-functions causes FAIL: gcc.c-torture/execute/builtins/pr22237.c execution zsojka at seznam dot cz
                   ` (6 preceding siblings ...)
  2010-07-23 11:36 ` rguenth at gcc dot gnu dot org
@ 2010-07-23 11:40 ` rguenth at gcc dot gnu dot org
  2010-07-24 19:49 ` joseph at codesourcery dot com
                   ` (3 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2010-07-23 11:40 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #7 from rguenth at gcc dot gnu dot org  2010-07-23 11:40 -------
Hm, no.  I think tree-nrv.c is correct.  I was playing with

Index: gcc/tree-nrv.c
===================================================================
--- gcc/tree-nrv.c      (revision 162450)
+++ gcc/tree-nrv.c      (working copy)
@@ -310,7 +310,8 @@ dest_safe_for_nrv_p (gimple call)
   if (TREE_CODE (dest) == SSA_NAME)
     return true;

-  if (call_may_clobber_ref_p (call, dest))
+  if (call_may_clobber_ref_p (call, dest)
+      || ref_maybe_used_by_stmt_p (call, dest))
     return false;

   return true;


but that's overly restrictive for something that is undefined even on the
gimple level.

Joseph, this is really triggering undefined behavior in C, does it?


-- 

rguenth at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jsm28 at gcc dot gnu dot org


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


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

* [Bug tree-optimization/43784] [4.6 Regression] -Os -fkeep-inline-functions causes FAIL: gcc.c-torture/execute/builtins/pr22237.c execution
  2010-04-18 16:25 [Bug tree-optimization/43784] New: [4.6 Regression] -Os -fkeep-inline-functions causes FAIL: gcc.c-torture/execute/builtins/pr22237.c execution zsojka at seznam dot cz
                   ` (7 preceding siblings ...)
  2010-07-23 11:40 ` rguenth at gcc dot gnu dot org
@ 2010-07-24 19:49 ` joseph at codesourcery dot com
  2010-07-26 15:06 ` matz at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: joseph at codesourcery dot com @ 2010-07-24 19:49 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #8 from joseph at codesourcery dot com  2010-07-24 19:49 -------
Subject: Re:  [4.6 Regression] -Os
 -fkeep-inline-functions causes FAIL: gcc.c-torture/execute/builtins/pr22237.c
 execution

On Fri, 23 Jul 2010, rguenth at gcc dot gnu dot org wrote:

> Joseph, this is really triggering undefined behavior in C, does it?

I don't see anything undefined here.  Remember that a return is not an 
assignment and it's only direct assignments of overlapping values that are 
disallowed (in N1256 this is 6.8.6.4 paragraph 4 and footnote 139; this 
was added in C90 TC1 following DR#001).


-- 


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


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

* [Bug tree-optimization/43784] [4.6 Regression] -Os -fkeep-inline-functions causes FAIL: gcc.c-torture/execute/builtins/pr22237.c execution
  2010-04-18 16:25 [Bug tree-optimization/43784] New: [4.6 Regression] -Os -fkeep-inline-functions causes FAIL: gcc.c-torture/execute/builtins/pr22237.c execution zsojka at seznam dot cz
                   ` (8 preceding siblings ...)
  2010-07-24 19:49 ` joseph at codesourcery dot com
@ 2010-07-26 15:06 ` matz at gcc dot gnu dot org
  2010-07-26 16:02 ` rguenth at gcc dot gnu dot org
  2010-07-26 16:02 ` rguenth at gcc dot gnu dot org
  11 siblings, 0 replies; 13+ messages in thread
From: matz at gcc dot gnu dot org @ 2010-07-26 15:06 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #9 from matz at gcc dot gnu dot org  2010-07-26 15:06 -------
Here's a testcase (nicer in the sense of not requiring inlining) that shows
the current compiler botching the nrv <-> retslot optimizations:

struct S {int x, y, makemelarge[5];};
S __attribute__((noinline)) f (S &s) {
  S r;
  r.x = s.y;
  r.y = s.x;
  return r;
}
int __attribute__((noinline)) glob (int a, int b)
{
  S local = { a, b };
  local = f (local);
  return local.y;
}
extern "C" void abort (void);
int main (void)
{
  if (glob (1, 3) != 1)
    abort ();
  return 0;
}


-- 


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


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

* [Bug tree-optimization/43784] [4.6 Regression] -Os -fkeep-inline-functions causes FAIL: gcc.c-torture/execute/builtins/pr22237.c execution
  2010-04-18 16:25 [Bug tree-optimization/43784] New: [4.6 Regression] -Os -fkeep-inline-functions causes FAIL: gcc.c-torture/execute/builtins/pr22237.c execution zsojka at seznam dot cz
                   ` (10 preceding siblings ...)
  2010-07-26 16:02 ` rguenth at gcc dot gnu dot org
@ 2010-07-26 16:02 ` rguenth at gcc dot gnu dot org
  11 siblings, 0 replies; 13+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2010-07-26 16:02 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #10 from rguenth at gcc dot gnu dot org  2010-07-26 16:02 -------
Subject: Bug 43784

Author: rguenth
Date: Mon Jul 26 16:01:55 2010
New Revision: 162539

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=162539
Log:
2010-07-26  Richard Guenther  <rguenther@suse.de>

        PR tree-optimization/43784
        * tree-nrv.c (dest_safe_for_nrv_p): It's not safe to NRV
        if the destination is used by the call.

        * gcc.c-torture/execute/pr43784.c: New testcase.
        * g++.dg/torture/pr43784.C: Likewise.

Added:
    trunk/gcc/testsuite/g++.dg/torture/pr43784.C
    trunk/gcc/testsuite/gcc.c-torture/execute/pr43784.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/tree-nrv.c


-- 


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


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

* [Bug tree-optimization/43784] [4.6 Regression] -Os -fkeep-inline-functions causes FAIL: gcc.c-torture/execute/builtins/pr22237.c execution
  2010-04-18 16:25 [Bug tree-optimization/43784] New: [4.6 Regression] -Os -fkeep-inline-functions causes FAIL: gcc.c-torture/execute/builtins/pr22237.c execution zsojka at seznam dot cz
                   ` (9 preceding siblings ...)
  2010-07-26 15:06 ` matz at gcc dot gnu dot org
@ 2010-07-26 16:02 ` rguenth at gcc dot gnu dot org
  2010-07-26 16:02 ` rguenth at gcc dot gnu dot org
  11 siblings, 0 replies; 13+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2010-07-26 16:02 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #11 from rguenth at gcc dot gnu dot org  2010-07-26 16:02 -------
Fixed.


-- 

rguenth at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |FIXED


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


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

end of thread, other threads:[~2010-07-26 16:02 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-04-18 16:25 [Bug tree-optimization/43784] New: [4.6 Regression] -Os -fkeep-inline-functions causes FAIL: gcc.c-torture/execute/builtins/pr22237.c execution zsojka at seznam dot cz
2010-04-18 16:26 ` [Bug tree-optimization/43784] " zsojka at seznam dot cz
2010-04-18 18:17 ` rguenth at gcc dot gnu dot org
2010-05-22 17:12 ` zsojka at seznam dot cz
2010-05-22 17:33 ` zsojka at seznam dot cz
2010-06-11 21:03 ` zsojka at seznam dot cz
2010-07-23 11:20 ` rguenth at gcc dot gnu dot org
2010-07-23 11:36 ` rguenth at gcc dot gnu dot org
2010-07-23 11:40 ` rguenth at gcc dot gnu dot org
2010-07-24 19:49 ` joseph at codesourcery dot com
2010-07-26 15:06 ` matz at gcc dot gnu dot org
2010-07-26 16:02 ` rguenth at gcc dot gnu dot org
2010-07-26 16:02 ` rguenth 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).