From owner-freebsd-current Sat Dec 23 09:20:34 1995 Return-Path: owner-current Received: (from root@localhost) by freefall.freebsd.org (8.7.3/8.7.3) id JAA22033 for current-outgoing; Sat, 23 Dec 1995 09:20:34 -0800 (PST) Received: from sivka.carrier.kiev.ua (root@sivka.carrier.kiev.ua [193.125.68.130]) by freefall.freebsd.org (8.7.3/8.7.3) with SMTP id JAA21915 for ; Sat, 23 Dec 1995 09:19:37 -0800 (PST) Received: from elvisti.kiev.ua (uucp@localhost) by sivka.carrier.kiev.ua (Sendmail 8.who.cares/5) with UUCP id TAA01156 for current@freebsd.org; Sat, 23 Dec 1995 19:20:59 +0200 Received: from office.elvisti.kiev.ua (office.elvisti.kiev.ua [193.125.28.33]) by spider2.elvisti.kiev.ua (8.6.12/8.ElVisti) with ESMTP id TAA07925 for ; Sat, 23 Dec 1995 19:24:10 +0200 Received: (from stesin@localhost) by office.elvisti.kiev.ua (8.6.12/8.ElVisti) id TAA05535 for current@freebsd.org; Sat, 23 Dec 1995 19:24:10 +0200 From: "Andrew V. Stesin" Message-Id: <199512231724.TAA05535@office.elvisti.kiev.ua> Subject: (fwd) Fix for bug in all known versions of GCC To: current@freebsd.org Date: Sat, 23 Dec 1995 19:24:09 +0200 (EET) X-Mailer: ELM [version 2.4 PL24alpha5] Content-Type: text Sender: owner-current@freebsd.org Precedence: bulk ------- Forwarded Message Return-Path: Message-Id: Date: Tue, 19 Dec 95 20:50 CST From: Richard Henderson 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.