From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 25281 invoked by alias); 15 Jun 2011 18:57:23 -0000 Received: (qmail 25273 invoked by uid 22791); 15 Jun 2011 18:57:22 -0000 X-SWARE-Spam-Status: No, hits=-6.5 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_HI,SPF_HELO_PASS,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 15 Jun 2011 18:57:04 +0000 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p5FIv3P0029409 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 15 Jun 2011 14:57:03 -0400 Received: from tyan-ft48-01.lab.bos.redhat.com (tyan-ft48-01.lab.bos.redhat.com [10.16.42.4]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id p5FIv3WP012455 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Wed, 15 Jun 2011 14:57:03 -0400 Received: from tyan-ft48-01.lab.bos.redhat.com (localhost.localdomain [127.0.0.1]) by tyan-ft48-01.lab.bos.redhat.com (8.14.4/8.14.4) with ESMTP id p5FIv22W013274 for ; Wed, 15 Jun 2011 20:57:02 +0200 Received: (from jakub@localhost) by tyan-ft48-01.lab.bos.redhat.com (8.14.4/8.14.4/Submit) id p5FIv2vc013272 for gcc-patches@gcc.gnu.org; Wed, 15 Jun 2011 20:57:02 +0200 Date: Wed, 15 Jun 2011 20:40:00 -0000 From: Jakub Jelinek To: gcc-patches@gcc.gnu.org Subject: [PATCH] Call estimate_numbers_of_iterations after insert_range_assertions (PR tree-optimization/49419) Message-ID: <20110615185701.GL17079@tyan-ft48-01.lab.bos.redhat.com> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org X-SW-Source: 2011-06/txt/msg01179.txt.bz2 Hi! The following testcase is miscompiled e.g. on powerpc (not on x86_64/i686 due to different ivopts choices), because estimate_numbers_of_iterations was called before assert_exprs are added to the IL and gets info cached until adjust_range_with_scev, where using the original SSA_NAMEs leads to problems where VR changes might not be propagated properly. Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk/4.6? I'll work on followup improvements for the trunk afterwards. 2011-06-15 Jakub Jelinek PR tree-optimization/49419 * tree-vrp.c (execute_vrp): Call init_range_assertions before estimate_numbers_of_iterations, call free_number_of_iterations_estimates before calling remove_range_assertions. * gcc.c-torture/execute/pr49419.c: New test. --- gcc/tree-vrp.c.jj 2011-05-31 08:03:10.000000000 +0200 +++ gcc/tree-vrp.c 2011-06-15 17:25:32.000000000 +0200 @@ -7730,14 +7730,14 @@ execute_vrp (void) rewrite_into_loop_closed_ssa (NULL, TODO_update_ssa); scev_initialize (); + insert_range_assertions (); + /* Estimate number of iterations - but do not use undefined behavior for this. We can't do this lazily as other functions may compute this using undefined behavior. */ free_numbers_of_iterations_estimates (); estimate_numbers_of_iterations (false); - insert_range_assertions (); - to_remove_edges = VEC_alloc (edge, heap, 10); to_update_switch_stmts = VEC_alloc (switch_update, heap, 5); threadedge_initialize_values (); @@ -7746,6 +7746,8 @@ execute_vrp (void) ssa_propagate (vrp_visit_stmt, vrp_visit_phi_node); vrp_finalize (); + free_numbers_of_iterations_estimates (); + /* ASSERT_EXPRs must be removed before finalizing jump threads as finalizing jump threads calls the CFG cleanup code which does not properly handle ASSERT_EXPRs. */ --- gcc/testsuite/gcc.c-torture/execute/pr49419.c.jj 2011-06-15 18:06:43.000000000 +0200 +++ gcc/testsuite/gcc.c-torture/execute/pr49419.c 2011-06-15 18:05:18.000000000 +0200 @@ -0,0 +1,38 @@ +/* PR tree-optimization/49419 */ + +extern void abort (void); + +struct S { int w, x, y; } *t; + +int +foo (int n, int f, int *s, int m) +{ + int x, i, a; + if (n == -1) + return 0; + for (x = n, i = 0; t[x].w == f && i < m; i++) + x = t[x].x; + if (i == m) + abort (); + a = i + 1; + for (x = n; i > 0; i--) + { + s[i] = t[x].y; + x = t[x].x; + } + s[0] = x; + return a; +} + +int +main (void) +{ + int s[3], i; + struct S buf[3] = { { 1, 1, 2 }, { 0, 0, 0 }, { 0, 0, 0 } }; + t = buf; + if (foo (0, 1, s, 3) != 2) + abort (); + if (s[0] != 1 || s[1] != 2) + abort (); + return 0; +} Jakub