From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 7403 invoked by alias); 11 Dec 2012 18:19:58 -0000 Received: (qmail 7355 invoked by uid 48); 11 Dec 2012 18:19:42 -0000 From: "rakdver at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/55481] [4.8 regression] -O2 generates a wrong-code infinite loop in C++Benchmark's simple_types_constant_folding int8 xor test Date: Tue, 11 Dec 2012 18:19:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: middle-end X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: rakdver at gcc dot gnu.org X-Bugzilla-Status: ASSIGNED X-Bugzilla-Priority: P1 X-Bugzilla-Assigned-To: rguenth at gcc dot gnu.org X-Bugzilla-Target-Milestone: 4.8.0 X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2012-12/txt/msg01139.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55481 --- Comment #15 from Zdenek Dvorak 2012-12-11 18:19:40 UTC --- Created attachment 28928 --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=28928 A proposed patch This patch fixes the error (and also makes the code more clearly match what is described in the comments). Long story: we try to avoid rewriting computations that define bivs, as that is usually unnecessary. However, there is a special case where rewriting is still needed; e.g., loop { tmp = biv + 1; use (tmp); biv = tmp + 1; (*) } Ivopts may decide to eliminate the temporary variable tmp by expressing its use in some other way (based on a different biv, etc.). So, if we did not rewrite (*), it would refer to a variable that is no longer defined. And in this case, we used a wrong way of expressing the biv computation that may cause signed overflows. The patch makes us instead to fall back to the general rewriting case, which does not have this problem. Untested (beyond the single testcase + C-only bootstrap).