🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.gcc.bug
Article #6329

gcc 2.7.2 i386 strength-reduce bug fix

#6329
From: Richard Henderson
Date: Tue, 19 Dec 1995 00:00
71 lines
2457 bytes
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~
Technical Details
Message-ID: <m0tSEc8-0003ftC@atheist.tamu.edu>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 113d02,db91418d47b56eed,start
X-Google-Attributes: gid113d02,public
From: richard@atheist.tamu.edu (Richard Henderson)
Subject: gcc 2.7.2 i386 strength-reduce bug fix
Date: 1995/12/19
Message-ID: <m0tSEc8-0003ftC@atheist.tamu.edu>
X-Deja-AN: 122393819
distribution: gnu
sender: daemon@cis.ohio-state.edu
organization: GNUs Not Usenet
reply-to: rth@tamu.edu
newsgroups: gnu.gcc.bug