Bug 23567 - [3.4/4.0/4.1 regression] if-conversion causes wrong code
Summary: [3.4/4.0/4.1 regression] if-conversion causes wrong code
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: rtl-optimization (show other bugs)
Version: 4.0.2
: P1 critical
Target Milestone: 4.0.3
Assignee: Jakub Jelinek
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2005-08-25 21:43 UTC by Serge Belyshev
Modified: 2005-11-07 13:17 UTC (History)
7 users (show)

See Also:
Host:
Target:
Build:
Known to work: 3.3.3
Known to fail: 3.4.0 4.0.0 4.1.0
Last reconfirmed: 2005-08-29 17:15:43


Attachments
gcc41-pr23567.patch (828 bytes, patch)
2005-08-29 17:28 UTC, Jakub Jelinek
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Serge Belyshev 2005-08-25 21:43:28 UTC
This patch:

2003-11-02  Roger Sayle  <roger@eyesopen.com>

	PR optimization/10817
	* ifcvt.c (noce_emit_move_insn): Improve documentation comment.
	(noce_try_move): New function to optimize an if-the-else into an
	unconditional move, i.e. "if (a!=b) x=a; else x=b" into "x=a".
	(noce_process_if_block): Attempt simplification with noce_try_move.

causes wrong codegen for this testcase, (taken from debian bug #325050, see
bugs.debian.org/cgi-bin/bugreport.cgi?bug=325050 )

-----------------------------
struct
{
  int len;
  char *name;
} s;

int main (void)
{
  s.len = 0;
  s.name = "";
  if (s.name [s.len] != 0)
    s.name [s.len] = 0;
  return 0;
}
-----------------------------

This looks very similar to PR 13400.
Comment 1 Andrew Pinski 2005-08-25 21:48:06 UTC
I want to say this was fixed on the mainline by:
2005-05-18  Richard Henderson  <rth@redhat.com>

        PR 21541
        * ifcvt.c (noce_process_if_block): Avoid conversion when the
        memory destination is readonly.
Comment 2 Andrew Pinski 2005-08-25 23:21:39 UTC
This is also latent on the mainline too so I was wrong in saying RTH's patch fixed it.
Use -O1 -fno-tree-dominator-opts to reproduce it there.

Confirmed.
Comment 3 Debian GCC Maintainers 2005-08-29 09:37:04 UTC
reported as http://bugs.debian.org/325050
Comment 4 Jakub Jelinek 2005-08-29 17:28:00 UTC
Created attachment 9615 [details]
gcc41-pr23567.patch

Patch I have been playing with so far.	It tries harder to look for read-only
memory.  Also, the noce_try_cmove_arith looks wrong to me if write into X
may trap - noce_try_cmove_arith will write into X unconditionally and that's
what we are trying to avoid if write into X may trap.
Comment 5 Steven Bosscher 2005-10-25 16:24:15 UTC
Jakub, ping!

Are you going to post your patch from comment #4??
Comment 6 Mark Mitchell 2005-10-31 05:39:26 UTC
Elevating to P1; this is a serious wrong-code regression.
Comment 7 Steven Bosscher 2005-11-03 21:00:23 UTC
Jakub, ping!
What's up with this one?
Comment 8 Jakub Jelinek 2005-11-04 10:52:09 UTC
Sorry, haven't touched this for a while.
Testing a new patch, there have been other problems in noce_process_if_block.
Comment 9 Jakub Jelinek 2005-11-07 08:02:02 UTC
Subject: Bug 23567

Author: jakub
Date: Mon Nov  7 08:01:54 2005
New Revision: 106585

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=106585
Log:
	PR rtl-optimization/23567
	* ifcvt.c (noce_mem_write_may_trap_or_fault_p): New function.
	(noce_process_if_block): Don't do any optimizations except
	if (cond) x = x; if !set_b and write into orig_x may trap
	or fault.  Remove the MEM_READONLY_P check.

	* gcc.c-torture/execute/20051104-1.c: New test.

Added:
    trunk/gcc/testsuite/gcc.c-torture/execute/20051104-1.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/ifcvt.c
    trunk/gcc/testsuite/ChangeLog

Comment 10 Jakub Jelinek 2005-11-07 08:28:08 UTC
Subject: Bug 23567

Author: jakub
Date: Mon Nov  7 08:28:01 2005
New Revision: 106586

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=106586
Log:
	PR rtl-optimization/23567
	* ifcvt.c (noce_mem_write_may_trap_or_fault_p): New function.
	(noce_process_if_block): Don't do any optimizations except
	if (cond) x = x; if !set_b and write into orig_x may trap
	or fault.

	* gcc.c-torture/execute/20051104-1.c: New test.

Added:
    branches/gcc-4_0-branch/gcc/testsuite/gcc.c-torture/execute/20051104-1.c
Modified:
    branches/gcc-4_0-branch/gcc/ChangeLog
    branches/gcc-4_0-branch/gcc/ifcvt.c
    branches/gcc-4_0-branch/gcc/testsuite/ChangeLog

Comment 11 Andrew Pinski 2005-11-07 13:17:08 UTC
Fixed.