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
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.
Confirmed.
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.
Investigating.
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.
It was the fwprop merge that further disabled the optimization in the trunk. http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=118475
> 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?
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
Zdenek, any chance that your aliasing oracle can be used to fix these?
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.
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
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
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
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
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.
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