public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/58984] New: wrong code at -Os and above on x86_64-linux-gnu in 64-bit mode
@ 2013-11-04  1:47 su at cs dot ucdavis.edu
  2013-11-04  7:52 ` [Bug tree-optimization/58984] [4.8/4.9 Regression] " mpolacek at gcc dot gnu.org
                   ` (10 more replies)
  0 siblings, 11 replies; 12+ messages in thread
From: su at cs dot ucdavis.edu @ 2013-11-04  1:47 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 58984
           Summary: wrong code at -Os and above on x86_64-linux-gnu in
                    64-bit mode
           Product: gcc
           Version: 4.9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: su at cs dot ucdavis.edu

The current gcc trunk and 4.8.x miscompile the following code on x86_64-linux
at -Os and above in 64-bit mode. 

This is a regression from 4.7.x. 

$ gcc-trunk -v
Using built-in specs.
COLLECT_GCC=gcc-trunk
COLLECT_LTO_WRAPPER=/usr/local/gcc-trunk/libexec/gcc/x86_64-unknown-linux-gnu/4.9.0/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: ../gcc-trunk/configure
--enable-languages=c,c++,objc,obj-c++,fortran,lto --disable-werror
--enable-checking=release --with-gmp=/usr/local/gcc-trunk
--with-mpfr=/usr/local/gcc-trunk --with-mpc=/usr/local/gcc-trunk
--with-cloog=/usr/local/gcc-trunk --prefix=/usr/local/gcc-trunk
Thread model: posix
gcc version 4.9.0 20131103 (experimental) [trunk revision 204333] (GCC) 
$ 
$ gcc-trunk -O1 small.c; a.out
1
$ gcc-trunk -Os small.c; a.out
0
$ gcc-4.8.2 -Os small.c; a.out
0
$ gcc-4.7.3 -Os small.c; a.out
1
$ 

--------------------------------

int printf (const char *, ...);

struct S
{
  int f0:8;
  int:6;
  int f1:5;
};

int a, *c = &a, e, n, b;

static int
foo (struct S p)
{
  const unsigned short *f[36];
  for (; e < 2; e++)
    {
      const unsigned short **i = &f[0];
      *c ^= 1;
      if (p.f1)
    {
      *i = 0;
      return b;
    }
    }
  return 0;
}

int
main ()
{
  struct S o = { 1, 1 };
  foo (o);
  n || o.f0;
  printf ("%d\n", a);
  return 0;
}


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

* [Bug tree-optimization/58984] [4.8/4.9 Regression] wrong code at -Os and above on x86_64-linux-gnu in 64-bit mode
  2013-11-04  1:47 [Bug tree-optimization/58984] New: wrong code at -Os and above on x86_64-linux-gnu in 64-bit mode su at cs dot ucdavis.edu
@ 2013-11-04  7:52 ` mpolacek at gcc dot gnu.org
  2013-11-04  7:53 ` mpolacek at gcc dot gnu.org
                   ` (9 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2013-11-04  7:52 UTC (permalink / raw)
  To: gcc-bugs

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

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2013-11-04
                 CC|                            |mpolacek at gcc dot gnu.org
            Summary|wrong code at -Os and above |[4.8/4.9 Regression] wrong
                   |on x86_64-linux-gnu in      |code at -Os and above on
                   |64-bit mode                 |x86_64-linux-gnu in 64-bit
                   |                            |mode
     Ever confirmed|0                           |1

--- Comment #1 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Confirmed.


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

* [Bug tree-optimization/58984] [4.8/4.9 Regression] wrong code at -Os and above on x86_64-linux-gnu in 64-bit mode
  2013-11-04  1:47 [Bug tree-optimization/58984] New: wrong code at -Os and above on x86_64-linux-gnu in 64-bit mode su at cs dot ucdavis.edu
  2013-11-04  7:52 ` [Bug tree-optimization/58984] [4.8/4.9 Regression] " mpolacek at gcc dot gnu.org
@ 2013-11-04  7:53 ` mpolacek at gcc dot gnu.org
  2013-11-04  7:59 ` jakub at gcc dot gnu.org
                   ` (8 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2013-11-04  7:53 UTC (permalink / raw)
  To: gcc-bugs

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

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |4.8.4


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

* [Bug tree-optimization/58984] [4.8/4.9 Regression] wrong code at -Os and above on x86_64-linux-gnu in 64-bit mode
  2013-11-04  1:47 [Bug tree-optimization/58984] New: wrong code at -Os and above on x86_64-linux-gnu in 64-bit mode su at cs dot ucdavis.edu
  2013-11-04  7:52 ` [Bug tree-optimization/58984] [4.8/4.9 Regression] " mpolacek at gcc dot gnu.org
  2013-11-04  7:53 ` mpolacek at gcc dot gnu.org
@ 2013-11-04  7:59 ` jakub at gcc dot gnu.org
  2013-11-04  8:10 ` jakub at gcc dot gnu.org
                   ` (7 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: jakub at gcc dot gnu.org @ 2013-11-04  7:59 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|2013-11-04 00:00:00         |
                 CC|                            |jakub at gcc dot gnu.org,
                   |                            |jamborm at gcc dot gnu.org
   Target Milestone|4.8.4                       |4.8.3

--- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Started with r193298.


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

* [Bug tree-optimization/58984] [4.8/4.9 Regression] wrong code at -Os and above on x86_64-linux-gnu in 64-bit mode
  2013-11-04  1:47 [Bug tree-optimization/58984] New: wrong code at -Os and above on x86_64-linux-gnu in 64-bit mode su at cs dot ucdavis.edu
                   ` (2 preceding siblings ...)
  2013-11-04  7:59 ` jakub at gcc dot gnu.org
@ 2013-11-04  8:10 ` jakub at gcc dot gnu.org
  2013-11-04  8:15 ` jakub at gcc dot gnu.org
                   ` (6 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: jakub at gcc dot gnu.org @ 2013-11-04  8:10 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
So, before IPA-CP, foo had:
  _10 = BIT_FIELD_REF <p, 32, 0>;
  _11 = _10 & 507904;
Now, IPA-CP does:
Modification phase of node foo.constprop.0/3
     Aggregate replacements: 0[14]=1, 0[8]=0, 0[0]=1
  _4 = 1;
  _5 = _4 & 507904;
which is of course wrong, because 32 bits at offset 0 in the structure should
contain value 16385 ((1 << 0) | (1 << 14)), rather than 1.


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

* [Bug tree-optimization/58984] [4.8/4.9 Regression] wrong code at -Os and above on x86_64-linux-gnu in 64-bit mode
  2013-11-04  1:47 [Bug tree-optimization/58984] New: wrong code at -Os and above on x86_64-linux-gnu in 64-bit mode su at cs dot ucdavis.edu
                   ` (3 preceding siblings ...)
  2013-11-04  8:10 ` jakub at gcc dot gnu.org
@ 2013-11-04  8:15 ` jakub at gcc dot gnu.org
  2013-11-04 14:39 ` jakub at gcc dot gnu.org
                   ` (5 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: jakub at gcc dot gnu.org @ 2013-11-04  8:15 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Note that likely since r199252 Aggregate replacements: 0[14]=1, 0[8]=0, 0[0]=1
is replaced with just 0[0]=1, still the effect is exactly the same.


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

* [Bug tree-optimization/58984] [4.8/4.9 Regression] wrong code at -Os and above on x86_64-linux-gnu in 64-bit mode
  2013-11-04  1:47 [Bug tree-optimization/58984] New: wrong code at -Os and above on x86_64-linux-gnu in 64-bit mode su at cs dot ucdavis.edu
                   ` (4 preceding siblings ...)
  2013-11-04  8:15 ` jakub at gcc dot gnu.org
@ 2013-11-04 14:39 ` jakub at gcc dot gnu.org
  2013-11-04 16:26 ` jamborm at gcc dot gnu.org
                   ` (4 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: jakub at gcc dot gnu.org @ 2013-11-04 14:39 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Ah, the reason why r199252 doesn't fix this is that esra changes o.f0 = 1;
into a MEM_REF, essentially *(char *)&o = 1, because the f0 has 8 bits.
So, determine_known_aggregate_parts doesn't consider the o.f0 = 1 store as
bitfield access.
If in the testcase int f0:8 is replaced with char f0, then it is miscompiled
even at -O2, and then of course o.f0 = 1 is not a bitfield, but still, it
overlaps with the bit field representative of the other bitfields.
So, either the replacement code really needs to be taught about bitfields
anyway
(at least look not just at offset, but also size of the known value and not
optimize into a constant if the access is to some bits beyond the known value
extent), or the punting in determine_known_aggregate_parts would need to be
much more conservative.


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

* [Bug tree-optimization/58984] [4.8/4.9 Regression] wrong code at -Os and above on x86_64-linux-gnu in 64-bit mode
  2013-11-04  1:47 [Bug tree-optimization/58984] New: wrong code at -Os and above on x86_64-linux-gnu in 64-bit mode su at cs dot ucdavis.edu
                   ` (5 preceding siblings ...)
  2013-11-04 14:39 ` jakub at gcc dot gnu.org
@ 2013-11-04 16:26 ` jamborm at gcc dot gnu.org
  2013-11-04 16:29 ` jakub at gcc dot gnu.org
                   ` (3 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: jamborm at gcc dot gnu.org @ 2013-11-04 16:26 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from Martin Jambor <jamborm at gcc dot gnu.org> ---
As far as I'm concerned, the patch is fine.  Thanks for taking care of it.


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

* [Bug tree-optimization/58984] [4.8/4.9 Regression] wrong code at -Os and above on x86_64-linux-gnu in 64-bit mode
  2013-11-04  1:47 [Bug tree-optimization/58984] New: wrong code at -Os and above on x86_64-linux-gnu in 64-bit mode su at cs dot ucdavis.edu
                   ` (6 preceding siblings ...)
  2013-11-04 16:26 ` jamborm at gcc dot gnu.org
@ 2013-11-04 16:29 ` jakub at gcc dot gnu.org
  2013-11-05 12:07 ` jakub at gcc dot gnu.org
                   ` (2 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: jakub at gcc dot gnu.org @ 2013-11-04 16:29 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #8 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Well, there is if (*size_p) which should have been if (size_p) obviously,
redoing bootstrap now with that fix.


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

* [Bug tree-optimization/58984] [4.8/4.9 Regression] wrong code at -Os and above on x86_64-linux-gnu in 64-bit mode
  2013-11-04  1:47 [Bug tree-optimization/58984] New: wrong code at -Os and above on x86_64-linux-gnu in 64-bit mode su at cs dot ucdavis.edu
                   ` (7 preceding siblings ...)
  2013-11-04 16:29 ` jakub at gcc dot gnu.org
@ 2013-11-05 12:07 ` jakub at gcc dot gnu.org
  2013-11-05 12:13 ` jakub at gcc dot gnu.org
  2013-11-07 20:15 ` law at redhat dot com
  10 siblings, 0 replies; 12+ messages in thread
From: jakub at gcc dot gnu.org @ 2013-11-05 12:07 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #9 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Author: jakub
Date: Tue Nov  5 12:05:37 2013
New Revision: 204385

URL: http://gcc.gnu.org/viewcvs?rev=204385&root=gcc&view=rev
Log:
    PR tree-optimization/58984
    * ipa-prop.c (ipa_load_from_parm_agg_1): Add SIZE_P argument,
    set *SIZE_P if non-NULL on success.
    (ipa_load_from_parm_agg, ipa_analyze_indirect_call_uses): Adjust
    callers.
    (ipcp_transform_function): Likewise.  Punt if size of access
    is different from TYPE_SIZE on v->value's type.

    * gcc.c-torture/execute/pr58984.c: New test.

Added:
    trunk/gcc/testsuite/gcc.c-torture/execute/pr58984.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/ipa-prop.c
    trunk/gcc/testsuite/ChangeLog


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

* [Bug tree-optimization/58984] [4.8/4.9 Regression] wrong code at -Os and above on x86_64-linux-gnu in 64-bit mode
  2013-11-04  1:47 [Bug tree-optimization/58984] New: wrong code at -Os and above on x86_64-linux-gnu in 64-bit mode su at cs dot ucdavis.edu
                   ` (8 preceding siblings ...)
  2013-11-05 12:07 ` jakub at gcc dot gnu.org
@ 2013-11-05 12:13 ` jakub at gcc dot gnu.org
  2013-11-07 20:15 ` law at redhat dot com
  10 siblings, 0 replies; 12+ messages in thread
From: jakub at gcc dot gnu.org @ 2013-11-05 12:13 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #10 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Author: jakub
Date: Tue Nov  5 12:11:17 2013
New Revision: 204387

URL: http://gcc.gnu.org/viewcvs?rev=204387&root=gcc&view=rev
Log:
    PR tree-optimization/58984
    * ipa-prop.c (ipa_load_from_parm_agg_1): Add SIZE_P argument,
    set *SIZE_P if non-NULL on success.
    (ipa_load_from_parm_agg, ipa_analyze_indirect_call_uses): Adjust
    callers.
    (ipcp_transform_function): Likewise.  Punt if size of access
    is different from TYPE_SIZE on v->value's type.

    * gcc.c-torture/execute/pr58984.c: New test.

Added:
    branches/gcc-4_8-branch/gcc/testsuite/gcc.c-torture/execute/pr58984.c
Modified:
    branches/gcc-4_8-branch/gcc/ChangeLog
    branches/gcc-4_8-branch/gcc/ipa-prop.c
    branches/gcc-4_8-branch/gcc/testsuite/ChangeLog


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

* [Bug tree-optimization/58984] [4.8/4.9 Regression] wrong code at -Os and above on x86_64-linux-gnu in 64-bit mode
  2013-11-04  1:47 [Bug tree-optimization/58984] New: wrong code at -Os and above on x86_64-linux-gnu in 64-bit mode su at cs dot ucdavis.edu
                   ` (9 preceding siblings ...)
  2013-11-05 12:13 ` jakub at gcc dot gnu.org
@ 2013-11-07 20:15 ` law at redhat dot com
  10 siblings, 0 replies; 12+ messages in thread
From: law at redhat dot com @ 2013-11-07 20:15 UTC (permalink / raw)
  To: gcc-bugs

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

Jeffrey A. Law <law at redhat dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
                 CC|                            |law at redhat dot com
         Resolution|---                         |FIXED

--- Comment #11 from Jeffrey A. Law <law at redhat dot com> ---
Fixed on trunk.


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

end of thread, other threads:[~2013-11-07 20:15 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-11-04  1:47 [Bug tree-optimization/58984] New: wrong code at -Os and above on x86_64-linux-gnu in 64-bit mode su at cs dot ucdavis.edu
2013-11-04  7:52 ` [Bug tree-optimization/58984] [4.8/4.9 Regression] " mpolacek at gcc dot gnu.org
2013-11-04  7:53 ` mpolacek at gcc dot gnu.org
2013-11-04  7:59 ` jakub at gcc dot gnu.org
2013-11-04  8:10 ` jakub at gcc dot gnu.org
2013-11-04  8:15 ` jakub at gcc dot gnu.org
2013-11-04 14:39 ` jakub at gcc dot gnu.org
2013-11-04 16:26 ` jamborm at gcc dot gnu.org
2013-11-04 16:29 ` jakub at gcc dot gnu.org
2013-11-05 12:07 ` jakub at gcc dot gnu.org
2013-11-05 12:13 ` jakub at gcc dot gnu.org
2013-11-07 20:15 ` law at redhat dot com

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