[Bug tree-optimization/43784] [4.6 Regression] -Os -fkeep-inline-functions causes FAIL: gcc.c-torture/execute/builtins/pr22237.c execution

2010-07-26 Thread matz at gcc dot gnu dot org


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



[Bug tree-optimization/43784] [4.6 Regression] -Os -fkeep-inline-functions causes FAIL: gcc.c-torture/execute/builtins/pr22237.c execution

2010-07-26 Thread rguenth at gcc dot gnu dot org


--- 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=gccview=revrev=162539
Log:
2010-07-26  Richard Guenther  rguent...@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



[Bug tree-optimization/43784] [4.6 Regression] -Os -fkeep-inline-functions causes FAIL: gcc.c-torture/execute/builtins/pr22237.c execution

2010-07-26 Thread rguenth at gcc dot gnu dot org


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



[Bug tree-optimization/43784] [4.6 Regression] -Os -fkeep-inline-functions causes FAIL: gcc.c-torture/execute/builtins/pr22237.c execution

2010-07-24 Thread joseph at codesourcery dot com


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



[Bug tree-optimization/43784] [4.6 Regression] -Os -fkeep-inline-functions causes FAIL: gcc.c-torture/execute/builtins/pr22237.c execution

2010-07-23 Thread rguenth at gcc dot gnu dot org


--- 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|-00-00 00:00:00 |2010-07-23 11:20:14
   date||


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



[Bug tree-optimization/43784] [4.6 Regression] -Os -fkeep-inline-functions causes FAIL: gcc.c-torture/execute/builtins/pr22237.c execution

2010-07-23 Thread rguenth at gcc dot gnu dot org


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



[Bug tree-optimization/43784] [4.6 Regression] -Os -fkeep-inline-functions causes FAIL: gcc.c-torture/execute/builtins/pr22237.c execution

2010-07-23 Thread rguenth at gcc dot gnu dot org


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



[Bug tree-optimization/43784] [4.6 Regression] -Os -fkeep-inline-functions causes FAIL: gcc.c-torture/execute/builtins/pr22237.c execution

2010-06-11 Thread zsojka at seznam dot cz


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



[Bug tree-optimization/43784] [4.6 Regression] -Os -fkeep-inline-functions causes FAIL: gcc.c-torture/execute/builtins/pr22237.c execution

2010-05-22 Thread zsojka at seznam dot cz


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



[Bug tree-optimization/43784] [4.6 Regression] -Os -fkeep-inline-functions causes FAIL: gcc.c-torture/execute/builtins/pr22237.c execution

2010-05-22 Thread zsojka at seznam dot cz


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



[Bug tree-optimization/43784] [4.6 Regression] -Os -fkeep-inline-functions causes FAIL: gcc.c-torture/execute/builtins/pr22237.c execution

2010-04-18 Thread zsojka at seznam dot cz


--- 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=20409action=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



[Bug tree-optimization/43784] [4.6 Regression] -Os -fkeep-inline-functions causes FAIL: gcc.c-torture/execute/builtins/pr22237.c execution

2010-04-18 Thread rguenth at gcc dot gnu dot org


-- 

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