Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 23 Dec 1995 19:24:09 +0200 (EET)
From:      "Andrew V. Stesin" <stesin@elvisti.kiev.ua>
To:        current@freebsd.org
Subject:   (fwd) Fix for bug in all known versions of GCC 
Message-ID:  <199512231724.TAA05535@office.elvisti.kiev.ua>

next in thread | raw e-mail | index | archive | help
------- Forwarded Message

Return-Path: 
Message-Id: <m0tSEc8-0003ftC@atheist.tamu.edu>
Date: Tue, 19 Dec 95 20:50 CST
From: Richard Henderson <richard@atheist.tamu.edu>
To: bug-gcc@prep.ai.mit.edu
Cc: mmex@shadowland.res.cmu.edu, linux-kernel@vger.rutgers.edu
Reply-To: rth@tamu.edu
Subject: gcc 2.7.2 i386 strength-reduce bug fix
Sender: owner-linux-kernel@vger.rutgers.edu

The strength-reduction optimization in gcc 2.7.2 (and earlier) can
produce incorrect code on the i386 platform.

The problem is that the giv chosen to eliminate a biv may overflow,
causing comparisons to fail.  The temporary solution is to simply
prevent the elimination.  A more complete solution would use initial
and final value information to assert that the replacement remains in
range for the type.

Another way the optimization might be retained is if the loop is
transformed to:

	if (x < end) { do { ... } while (x != end); }

Naturally, there are some severe restrictions on when this might be
used, but a number of simple ones (such as the example below) that
could benefit.

Here is an example that reproduces the bug:
- ------------------------------------------------------------
int A[3];
unsigned int B = 3;
 
void printit(void)
{
    int i;
    for(i = 0; i < B; i++)
	printf("A[%d] = %d\n", i, A[i]);
}
 
int main()
{
    int i;
    for(i = 0; i < B; i++)
	A[i] = i-3;
    printit();
    return 0;
}
- ------------------------------------------------------------

Here is a patch that defeats the elimination of a biv involved in a
comparison. 
- ------------------------------------------------------------
*** loop.c.orig	Tue Oct  3 11:17:16 1995
- --- loop.c	Tue Dec 19 19:38:29 1995
*************** maybe_eliminate_biv_1 (x, insn, bl, elim
*** 6119,6124 ****
- --- 6119,6127 ----
        else
  	break;
  
+       /* Unless we can assert that the replacement giv does not 
+          overflow, we cannot (simply) eliminate the biv. */
+ #if 0
        if (CONSTANT_P (arg))
  	{
  	  /* First try to replace with any giv that has constant positive
*************** maybe_eliminate_biv_1 (x, insn, bl, elim
*** 6264,6269 ****
- --- 6267,6273 ----
  	    }
  #endif
  	}
+ #endif
  
        /* If we get here, the biv can't be eliminated.  */
        return 0;
- ------------------------------------------------------------


r~

------- End of Forwarded Message
-- 

	With best regards -- Andrew Stesin.

	+380 (44) 2760188	+380 (44) 2713457	+380 (44) 2713560

	An undocumented feature is a coding error.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199512231724.TAA05535>