From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 30186 invoked by alias); 20 Nov 2013 12:08:26 -0000 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 Received: (qmail 30151 invoked by uid 48); 20 Nov 2013 12:08:23 -0000 From: "rguenth at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/59058] [4.7/4.8/4.9 Regression] wrong code at -O3 on x86_64-linux-gnu (affecting gcc 4.6 to trunk) Date: Wed, 20 Nov 2013 12:08:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: tree-optimization X-Bugzilla-Version: 4.9.0 X-Bugzilla-Keywords: wrong-code X-Bugzilla-Severity: normal X-Bugzilla-Who: rguenth at gcc dot gnu.org X-Bugzilla-Status: ASSIGNED X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: rguenth at gcc dot gnu.org X-Bugzilla-Target-Milestone: 4.7.4 X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2013-11/txt/msg01996.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59058 --- Comment #5 from Richard Biener --- Unfortunately @@ -2930,11 +2931,31 @@ number_of_exit_cond_executions (struct l if (chrec_contains_undetermined (ret)) return ret; - ret = chrec_fold_plus (type, ret, build_int_cst (type, 1)); - if (TREE_CODE (ret) == INTEGER_CST - && TREE_OVERFLOW (ret)) + /* Handle constants without widening. */ + if (TREE_CODE (ret) == INTEGER_CST) + { + double_int adj = tree_to_double_int (ret) + double_int_one; + if (double_int_fits_to_tree_p (type, adj)) + return double_int_to_tree (type, adj); + } + + /* For the remaining case widen to an unsigned type from a + signed one or to one with at least one bit more precision + but not larger than using word_mode. */ + if (!TYPE_UNSIGNED (type)) + type = unsigned_type_for (type); + else if (GET_MODE_CLASS (TYPE_MODE (type)) == MODE_INT + && TYPE_PRECISION (type) < GET_MODE_PRECISION (word_mode)) + { + enum machine_mode mode; + mode = smallest_mode_for_size (TYPE_PRECISION (type) + 1, MODE_INT); + type = build_nonstandard_integer_type (GET_MODE_PRECISION (mode), 1); + } + else return chrec_dont_know; + ret = chrec_convert (type, ret, NULL); + ret = chrec_fold_plus (type, ret, build_int_cst (type, 1)); return ret; } breaks loops which use size_t as induction variable type. But they are possibly miscompiled anyway. Not sure if we can rely on the availability of arithmetics on modes > word_mode, can we?