Bug 30643 - [4.1/4.2/4.3 regression] CSE pessimization
Summary: [4.1/4.2/4.3 regression] CSE pessimization
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: rtl-optimization (show other bugs)
Version: 4.3.0
: P2 normal
Target Milestone: 4.1.3
Assignee: Alexandre Oliva
URL:
Keywords: alias, missed-optimization
Depends on: 32275
Blocks:
  Show dependency treegraph
 
Reported: 2007-01-30 17:06 UTC by Dan Nicolaescu
Modified: 2007-06-10 20:58 UTC (History)
6 users (show)

See Also:
Host:
Target:
Build:
Known to work: 4.1.1
Known to fail: 4.1.2 4.2.0 4.3.0
Last reconfirmed: 2007-03-05 07:22:17


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Dan Nicolaescu 2007-01-30 17:06:56 UTC
CSE used to eliminate all the "if"s in the code below at least in gcc-3.x (and probably even earlier). Now in SVN HEAD it does not do it anymore. 4.1 still does it. 

struct s {  int a;  int b;};
void bar (struct s *ps,  int *p, int *__restrict__ rp, int *__restrict__ rq)
{
  ps->a = 0;
  ps->b = 1;
  if (ps->a != 0)    abort ();
  p[0] = 0;
  p[1] = 1;
  if (p[0] != 0)     abort ();
  rp[0] = 0;
  rq[0] = 1;
  if (rp[0] != 0)     abort();
}

-O2 assembly for SVN HEAD:
bar:
        subl    $12, %esp
        movl    16(%esp), %eax
        movl    20(%esp), %edx
        movl    24(%esp), %ecx
        movl    $0, (%eax)
        movl    $1, 4(%eax)
        movl    (%eax), %eax
        testl   %eax, %eax
        jne     .L20
        movl    $0, (%edx)
        movl    (%edx), %eax
        movl    $1, 4(%edx)
        testl   %eax, %eax
        jne     .L20
        movl    $0, (%ecx)
        movl    (%ecx), %ecx
        movl    28(%esp), %eax
        testl   %ecx, %ecx
        movl    $1, (%eax)
        jne     .L20
        addl    $12, %esp
        ret
.L20:
        call    abort


-O2 assembly for 4.1.1
bar:
        movl    4(%esp), %eax
        movl    8(%esp), %edx
        movl    $0, (%eax)
        movl    $1, 4(%eax)
        movl    12(%esp), %eax
        movl    $0, (%edx)
        movl    $1, 4(%edx)
        movl    $0, (%eax)
        movl    16(%esp), %eax
        movl    $1, (%eax)
        ret
Comment 1 Janis Johnson 2007-02-13 20:37:25 UTC
Dan requested a regression hunt for this.  An i686-linux cross compiler starts failing with this mainline patch:

    http://gcc.gnu.org/viewcvs?view=rev&rev=115614

    r115614 | pbrook | 2006-07-20 13:57:31 +0000 (Thu, 20 Jul 2006)

For powerpc-linux there are no calls to abort.
Comment 2 Richard Biener 2007-02-20 22:31:02 UTC
Confirmed.
Comment 3 Jakub Jelinek 2007-02-21 20:49:23 UTC
4.1.2 behaves the same way as 4.2/4.3, the PR27363 patch that caused this
is got committed even there, see http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=115620
Reverting that patch on gcc-4_1-branch restores the previous behavior.
Comment 4 Eric Botcazou 2007-03-05 07:22:17 UTC
Investigating.
Comment 5 Alexandre Oliva 2007-03-08 09:05:09 UTC
I have a patch for the 4.1 branch that I'm bootstrap-testing now.  It doesn't look like reverting the mentioned patch will fix the problem in mainline, though, at least for an x86_64-linux-gnu native.
Comment 6 Alexandre Oliva 2007-03-08 10:23:37 UTC
It was the fwprop merge that further disabled the optimization in the trunk.  http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=118475
Comment 7 Eric Botcazou 2007-03-08 11:39:50 UTC
> I have a patch for the 4.1 branch that I'm bootstrap-testing now.

OK, reassigning to you, thanks.

> It doesn't look like reverting the mentioned patch will fix the problem in
> mainline, though, at least for an x86_64-linux-gnu native.

I presume it works on the 4.2 branch though?
Comment 8 patchapp@dberlin.org 2007-03-09 06:50:30 UTC
Subject: Bug number PR30643

A patch for this bug has been added to the patch tracker.
The mailing list url for the patch is http://gcc.gnu.org/ml/gcc-patches/2007-03/msg00525.html
Comment 9 Paolo Bonzini 2007-03-09 08:44:05 UTC
Zdenek, any chance that your aliasing oracle can be used to fix these?
Comment 10 Zdenek Dvorak 2007-03-09 08:54:14 UTC
Alias oracle could be used for this; but my patch only uses it in loop optimizers.  So some changes to make ccp use it would be necessary.
Comment 11 patchapp@dberlin.org 2007-03-09 12:40:51 UTC
Subject: Bug number PR30643

A patch for this bug has been added to the patch tracker.
The mailing list url for the patch is http://gcc.gnu.org/ml/gcc-patches/2007-03/msg00545.html
Comment 12 Alexandre Oliva 2007-03-09 20:13:20 UTC
Subject: Bug 30643

Author: aoliva
Date: Fri Mar  9 20:13:10 2007
New Revision: 122760

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=122760
Log:
gcc/ChangeLog:
PR rtl-optimization/30643
* cse.c (cse_insn): Recompute dest_hash after insert_regs for
(fold_rtx): Recurse, like before 2006-11-03.
gcc/testsuite/ChangeLog:
PR rtl-optimization/30643
* gcc.dg/pr30643.c: New.

Added:
    trunk/gcc/testsuite/gcc.dg/pr30643.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/cse.c
    trunk/gcc/testsuite/ChangeLog

Comment 13 Alexandre Oliva 2007-03-09 23:30:01 UTC
Subject: Bug 30643

Author: aoliva
Date: Fri Mar  9 23:29:51 2007
New Revision: 122771

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=122771
Log:
gcc/ChangeLog:
PR rtl-optimization/30643
* cse.c (cse_insn): Recompute dest_hash after insert_regs for
dest_addr_elt.
gcc/testsuite/ChangeLog:
PR rtl-optimization/30643
* gcc.dg/pr30643.c: New.

Added:
    branches/gcc-4_2-branch/gcc/testsuite/gcc.dg/pr30643.c
Modified:
    branches/gcc-4_2-branch/gcc/ChangeLog
    branches/gcc-4_2-branch/gcc/cse.c
    branches/gcc-4_2-branch/gcc/testsuite/ChangeLog

Comment 14 Alexandre Oliva 2007-03-09 23:30:32 UTC
Subject: Bug 30643

Author: aoliva
Date: Fri Mar  9 23:30:16 2007
New Revision: 122772

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=122772
Log:
gcc/ChangeLog:
PR rtl-optimization/30643
* cse.c (cse_insn): Recompute dest_hash after insert_regs for
dest_addr_elt.
gcc/testsuite/ChangeLog:
PR rtl-optimization/30643
* gcc.dg/pr30643.c: New.

Added:
    branches/gcc-4_1-branch/gcc/testsuite/gcc.dg/pr30643.c
Modified:
    branches/gcc-4_1-branch/gcc/ChangeLog
    branches/gcc-4_1-branch/gcc/cse.c
    branches/gcc-4_1-branch/gcc/testsuite/ChangeLog

Comment 15 Alexandre Oliva 2007-03-09 23:36:05 UTC
Should be fixed now, but H-P Nilsson says on IRC that there is a new ICE in cse.c that could be related.  No details yet.  I suppose it's mainline, because the patches for the branches are so much more trivial.  We'll see.

Comment 16 patchapp@dberlin.org 2007-03-13 07:30:41 UTC
Subject: Bug number PR30643

A patch for this bug has been added to the patch tracker.
The mailing list url for the patch is http://gcc.gnu.org/ml/gcc-patches/2007-03/msg00815.html