Bug 40022 - [4.4 Regression] Alpine miscompilation
Summary: [4.4 Regression] Alpine miscompilation
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 4.4.0
: P1 normal
Target Milestone: 4.4.1
Assignee: Richard Biener
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2009-05-04 23:08 UTC by Joshua Daniel Franklin
Modified: 2009-05-06 08:32 UTC (History)
5 users (show)

See Also:
Host:
Target:
Build:
Known to work: 4.4.1 4.5.0
Known to fail: 4.4.0
Last reconfirmed: 2009-05-05 10:10:32


Attachments
alpine pith/reply.c compiled with O0 and save-temps (23.48 KB, text/plain)
2009-05-04 23:36 UTC, Joshua Daniel Franklin
Details
alpine pith/reply.c compiled with save-temps (64.64 KB, text/plain)
2009-05-05 00:00 UTC, Joshua Daniel Franklin
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Joshua Daniel Franklin 2009-05-04 23:08:30 UTC
Hello, I have to admit I'm clueless about how to debug this. 
On Fedora 11 preview release with gcc-4.4.0 alpine "reply to all"
does not include the list of cc'd addresses. Linus found that if
you compile the pith/reply.cc without optimizations it works 
properly (see Fedora bug report at 
http://bugzilla.redhat.com/show_bug.cgi?id=496400 ).

Here is how to reproduce:

mkdir alpinetest
cd alpinetest
svn checkout https://svn.cac.washington.edu/public/alpine/snapshots/
cd snapshots
_sysconfdir=/etc/
touch imap/ip6
./configure \  --enable-debug=no \
  --without-tcl \
  --with-c-client-target=lfd \
  --with-passfile=.alpine.passfile \
  --with-spellcheck-prog=aspell \
  --with-system-pinerc=%{_sysconfdir}/pine.conf \
  --with-system-fixed-pinerc=%{_sysconfdir}/pine.conf.fixed

make

alpine/alpine # try "Reply to all" and see bug

cd pith
make clean && make CFLAGS=-O0
cd ..
make
alpine/alpine # try "Reply to all" and see it working
Comment 1 Andrew Pinski 2009-05-04 23:16:20 UTC
Hmm, so -fwrapv and -fno-strict-aliasing fixes the problem which case it might be a bug in the source.

Can you provide the preprocessed source of pith/reply.cc?  
Comment 2 Joshua Daniel Franklin 2009-05-04 23:36:04 UTC
Created attachment 17798 [details]
alpine pith/reply.c compiled with O0 and save-temps
Comment 3 Andrew Pinski 2009-05-04 23:55:07 UTC
That is the assembler that is produced not the preprocessed source, use -save-temps and attach the .ii file. 

Thanks,
Andrew Pinski
Comment 4 Joshua Daniel Franklin 2009-05-05 00:00:20 UTC
Created attachment 17799 [details]
alpine pith/reply.c compiled with save-temps


'
My compile line:

gcc -c -save-temps -std=gnu99 -DHAVE_CONFIG_H   -I../include -I../include -I/etc/pki/tls/include   -c -o reply.o reply.c

Make output:

cc -save-temps -std=gnu99 -DHAVE_CONFIG_H   -I../include -I../include -I/etc/pki/tls/include   -O0 -MT reply.o -MD -MP -MF .deps/reply.Tpo -c -o reply.o reply.c
Comment 5 Joshua Daniel Franklin 2009-05-05 00:01:10 UTC
(In reply to comment #3)
> That is the assembler that is produced not the preprocessed source, use
> -save-temps and attach the .ii file. 

Sorry. Does this one look right? It's actually .c I typo'd the .cc.
Comment 6 Jakub Jelinek 2009-05-05 09:02:11 UTC
Reduced testcase:
extern void abort (void);

struct A
{
  struct A *a;
};

struct B
{
  struct A *b;
};

__attribute__((noinline))
struct A *
foo (struct A *x)
{
  asm volatile ("" : : "g" (x) : "memory");
  return x;
}

__attribute__((noinline))
void
bar (struct B *w, struct A *x, struct A *y, struct A *z)
{
  struct A **c;
  c = &w->b;
  *c = foo (x);
  while (*c)
    c = &(*c)->a;
  *c = foo (y);
  while (*c)
    c = &(*c)->a;
  *c = foo (z);
}

struct B d;
struct A e, f, g;

int
main (void)
{
  f.a = &g;
  bar (&d, &e, &f, 0);
  if (d.b == 0
      || d.b->a == 0
      || d.b->a->a == 0
      || d.b->a->a->a != 0)
    abort ();
  return 0;
}

Looking into it.
Comment 7 Jakub Jelinek 2009-05-05 10:01:32 UTC
Introduced during tuples merge apparently (haven't bisected the tuples branch though).
To me this looks like a phiprop bug.
In *.alias (trunk, -O2) we have:
  # BLOCK 3 freq:9100
  # PRED: 4 [91.0%]  (true,exec)
  # VUSE <.MEMD.2716_19>
  D.1614_8 = *cD.1606_1;
  cD.1606_9 = &D.1614_8->aD.1593;
  # SUCC: 4 [100.0%]  (fallthru,dfs_back,exec)

  # BLOCK 4 freq:10000
  # PRED: 2 [100.0%]  (fallthru,exec) 3 [100.0%]  (fallthru,dfs_back,exec)
  # cD.1606_1 = PHI <cD.1606_4(2), cD.1606_9(3)>
  # VUSE <.MEMD.2716_19>
  D.1614_7 = *cD.1606_1;
  if (D.1614_7 != 0B)
    goto <bb 3>;
  else
    goto <bb 5>;
  # SUCC: 3 [91.0%]  (true,exec) 5 [9.0%]  (false,exec)

  # BLOCK 5 freq:900
  # PRED: 4 [9.0%]  (false,exec)
  # .MEMD.2716_20 = VDEF <.MEMD.2716_19>
  D.1615_11 = fooD.1597 (yD.1602_10(D));
  # .MEMD.2716_21 = VDEF <.MEMD.2716_20>
  *cD.1606_1 = D.1615_11;
  goto <bb 7>;
  # SUCC: 7 [100.0%]  (fallthru,exec)

  # BLOCK 6 freq:9100
  # PRED: 7 [91.0%]  (true,exec)
  # VUSE <.MEMD.2716_21>
  D.1614_13 = *cD.1606_2;
  cD.1606_14 = &D.1614_13->aD.1593;
  # SUCC: 7 [100.0%]  (fallthru,dfs_back,exec)

  # BLOCK 7 freq:10000
  # PRED: 5 [100.0%]  (fallthru,exec) 6 [100.0%]  (fallthru,dfs_back,exec)
  # cD.1606_2 = PHI <cD.1606_1(5), cD.1606_14(6)>
  # VUSE <.MEMD.2716_21>
  D.1614_12 = *cD.1606_2;
  if (D.1614_12 != 0B)
    goto <bb 6>;
  else
    goto <bb 8>;
  # SUCC: 6 [91.0%]  (true,exec) 8 [9.0%]  (false,exec)

Note that the D.1614_12 = *cD.1606_2 read depends on the *cD.1606_1 = D.1615_11;
store.  In phiprop we have though:

  # BLOCK 3 freq:9100
  # PRED: 4 [91.0%]  (true,exec)
  cD.1606_9 = &D.1614_8->aD.1593;
  # VUSE <.MEMD.2716_19>
  D.2745_25 = D.1614_8->aD.1593;
  # SUCC: 4 [100.0%]  (fallthru,dfs_back,exec)

  # BLOCK 4 freq:10000
  # PRED: 2 [100.0%]  (fallthru,exec) 3 [100.0%]  (fallthru,dfs_back,exec)
  # cD.1606_1 = PHI <cD.1606_4(2), cD.1606_9(3)>
  # D.1614_8 = PHI <D.2744_24(2), D.2745_25(3)>
  D.1614_7 = D.1614_8;
  if (D.1614_7 != 0B)
    goto <bb 3>;
  else
    goto <bb 5>;
  # SUCC: 3 [91.0%]  (true,exec) 5 [9.0%]  (false,exec)

  # BLOCK 5 freq:900
  # PRED: 4 [9.0%]  (false,exec)
  # .MEMD.2716_20 = VDEF <.MEMD.2716_19>
  D.1615_11 = fooD.1597 (yD.1602_10(D));
  # .MEMD.2716_21 = VDEF <.MEMD.2716_20>
  *cD.1606_1 = D.1615_11;
  goto <bb 7>;
  # SUCC: 7 [100.0%]  (fallthru,exec)

  # BLOCK 6 freq:9100
  # PRED: 7 [91.0%]  (true,exec)
  cD.1606_14 = &D.1614_13->aD.1593;
  # VUSE <.MEMD.2716_21>
  D.2746_26 = D.1614_13->aD.1593;
  # SUCC: 7 [100.0%]  (fallthru,dfs_back,exec)

  # BLOCK 7 freq:10000
  # PRED: 5 [100.0%]  (fallthru,exec) 6 [100.0%]  (fallthru,dfs_back,exec)
  # cD.1606_2 = PHI <cD.1606_1(5), cD.1606_14(6)>
  # D.1614_13 = PHI <D.1614_8(5), D.2746_26(6)>
  D.1614_12 = D.1614_13;
  if (D.1614_12 != 0B)
    goto <bb 6>;
  else
    goto <bb 8>;
  # SUCC: 6 [91.0%]  (true,exec) 8 [9.0%]  (false,exec)

Note that the D.1614_13 PHI now uses D.1614_8, which is correct *c content
only if the *cD.1606_1 = D.1615_11; store wasn't performed.  This store
obviously can change what *c contains.  Later passes then find out that
D.1614_8 must be 0 to reach BB5 and BB7, so the whole second while loop is removed.
Comment 8 Richard Biener 2009-05-05 10:10:32 UTC
Mine.
Comment 9 Richard Biener 2009-05-05 16:10:03 UTC
Subject: Bug 40022

Author: rguenth
Date: Tue May  5 16:09:46 2009
New Revision: 147128

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=147128
Log:
2009-05-05  Richard Guenther  <rguenther@suse.de>

	PR tree-optimization/40022
	* tree-ssa-phiprop.c (struct phiprop_d): Exchange vop_stmt for
	the only vuse.
	(phivn_valid_p): Fix tuplification error, simplify.
	(phiprop_insert_phi): Add dumps.
	(propagate_with_phi): Simplify.

	* gcc.c-torture/execute/pr40022.c: New testcase.

Added:
    trunk/gcc/testsuite/gcc.c-torture/execute/pr40022.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/tree-ssa-phiprop.c

Comment 10 Richard Biener 2009-05-05 16:10:46 UTC
Fixed for trunk.
Comment 11 Mark Mitchell 2009-05-05 16:11:56 UTC
Richard, can this be closed now?
Comment 12 Jakub Jelinek 2009-05-05 16:53:58 UTC
It hasn't been fixed on the 4.4 branch yet, so it can't.
Comment 13 Richard Biener 2009-05-06 08:32:39 UTC
Fixed now.
Comment 14 Richard Biener 2009-05-06 08:33:25 UTC
Subject: Bug 40022

Author: rguenth
Date: Wed May  6 08:32:24 2009
New Revision: 147153

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=147153
Log:
2009-05-06  Richard Guenther  <rguenther@suse.de>

	PR tree-optimization/40022
	* tree-ssa-phiprop.c (phivn_valid_p): Fix tuplification error.

	* gcc.c-torture/execute/pr40022.c: New testcase.

Added:
    branches/gcc-4_4-branch/gcc/testsuite/gcc.c-torture/execute/pr40022.c
Modified:
    branches/gcc-4_4-branch/gcc/ChangeLog
    branches/gcc-4_4-branch/gcc/testsuite/ChangeLog
    branches/gcc-4_4-branch/gcc/tree-ssa-phiprop.c