Bug 16380 - [3.3/3.4 Regression] Use of uninitialised register after dbra conversion
[3.3/3.4 Regression] Use of uninitialised register after dbra conversion
Status: RESOLVED FIXED
Product: gcc
Classification: Unclassified
Component: rtl-optimization
3.4.1
: P2 normal
: 3.4.2
Assigned To: rsandifo@gcc.gnu.org
: wrong-code
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2004-07-06 08:40 UTC by rsandifo@gcc.gnu.org
Modified: 2005-07-23 22:49 UTC (History)
1 user (show)

See Also:
Host:
Target: mips64-elf
Build:
Known to work: 2.95.3 4.0.0
Known to fail: 3.0.4 3.2.3 3.3.4 3.4.1
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description rsandifo@gcc.gnu.org 2004-07-06 08:40:23 UTC
gcc-3.0 and above miscompile the following test case on mips64-elf
at -O2:

int main ()
{
  int i;
  for (i = 0; i < 10; i++)
    continue;
  if (i < 10)
    abort ();
  exit (0);
}

GCSE realises that the second i < 10 is redundant and reuses
the result of "i < 10" from the for(...) loop.  The loop
optimiser then converts the loop into decrement-and-branch
form and deletes the first comparison.  This leaves the
if (...) statement checking an uninitialised register:

        addiu   $sp,$sp,-40
        sd      $31,32($sp)
        li      $2,9
        addiu   $2,$2,-1
$L10:
        bgez    $2,$L10
        addiu   $2,$2,-1

        beq     $3,$0,$L6      # <---- $3 not initialised
        nop

        jal     abort
        nop

$L6:
        jal     exit
        move    $4,$0
Comment 1 rsandifo@gcc.gnu.org 2004-07-06 08:42:10 UTC
About to submit a patch.
Comment 2 CVS Commits 2004-07-06 18:27:41 UTC
Subject: Bug 16380

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	rsandifo@gcc.gnu.org	2004-07-06 18:27:35

Modified files:
	gcc            : ChangeLog loop.c 
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/gcc.c-torture/execute: 20040706-1.c 

Log message:
	PR rtl-optimization/16380
	* loop.c (check_dbra_loop): Sink comparison instructions if they
	do something other than set cc0.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=2.4324&r2=2.4325
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/loop.c.diff?cvsroot=gcc&r1=1.501&r2=1.502
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.3943&r2=1.3944
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.c-torture/execute/20040706-1.c.diff?cvsroot=gcc&r1=NONE&r2=1.1

Comment 4 rsandifo@gcc.gnu.org 2004-07-13 15:31:21 UTC
Patch applied.