From patchwork Tue Mar 4 08:26:19 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 326181 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 633072C00B3 for ; Tue, 4 Mar 2014 19:26:36 +1100 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:reply-to:mime-version :content-type; q=dns; s=default; b=d7apOEfjV+0hoisH1NmiVjeeHJX6D ZovgELNG5Fv/7S10KEx9v0IjnTiJdH51j2kFARzbpjcyF7lIbacit5sOVoDNRlkb 3n1yOz8au+PQ9UTJNl5Pm/BH+OyEDHM1jkat5+0w4EihB81HRGmluDk9rYuFCv8s XiqGcN5bxydImY= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:reply-to:mime-version :content-type; s=default; bh=Dr8DVIzaWGid0TaUpyy1GkSFqSc=; b=ZVN 6xSWnX/nCqV6HisYF/BQK36Piw8p/VApvKNOh1wJD344MhKU1FU8fP7LuuB/EA0v GRUeJMgWNmbBMfYQP49daU63NK3F1H7pE0TnRObbSAgTYvPB0iQ3OvYbPdPEeq6K mLs7Aj/uQO5RCICaX3VXWJbljO61GvC/+DJroos0= Received: (qmail 4134 invoked by alias); 4 Mar 2014 08:26:28 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 4117 invoked by uid 89); 4 Mar 2014 08:26:27 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.6 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 04 Mar 2014 08:26:25 +0000 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s248QNts004608 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 4 Mar 2014 03:26:24 -0500 Received: from tucnak.zalov.cz (ovpn-116-35.ams2.redhat.com [10.36.116.35]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id s248QL48002101 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Tue, 4 Mar 2014 03:26:22 -0500 Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.14.7/8.14.7) with ESMTP id s248QJpL011092; Tue, 4 Mar 2014 09:26:20 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.14.7/8.14.7/Submit) id s248QJif011091; Tue, 4 Mar 2014 09:26:19 +0100 Date: Tue, 4 Mar 2014 09:26:19 +0100 From: Jakub Jelinek To: Alexandre Oliva Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix up var-tracking regression (PR middle-end/60381) Message-ID: <20140304082619.GO22862@tucnak.redhat.com> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-IsSubscribed: yes Hi! This patch attempts to fix a regression caused by the http://gcc.gnu.org/r208220 change. In particular, because cselib_reset_table called immediately after cselib_preserve_only_values removes VALUEs with zero locs and thus clears n_useless_values, if we don't remove_useless_values right away (as was done before the patch), we might not call discard_useless_locs at all). The problem with that is var-tracking relies on preserved values not referencing non-preserved values without any locs. The patch ensures we discard_useless_locs at least sometimes during vt_initialize (if the cumulative number of dropped and useless VALUEs goes over certain amount) and ensures we do it at least once at the end of vt_initialize. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2014-03-04 Jakub Jelinek PR middle-end/60381 * cselib.h (cselib_remove_useless_values): New prototype. * var-tracking.c (vt_initialize): Call it at the end. * cselib.c (n_dropped_useless_values): New counter. (cselib_reset_table): Accumulate n_useless_values into n_dropped_useless_values. (remove_useless_values): Revert 2014-02-28 change. Clear n_dropped_useless_values. (cselib_preserve_only_values): Don't call remove_useless_values, just do traversal with discard_useless_locs conditionally on n_dropped_useless_values + n_useless_values being big enough. (cselib_remove_useless_values): New function. (cselib_process_insn): Revert 2014-02-28 change. (cselib_finish): Clear n_dropped_useless_values. Jakub --- gcc/cselib.h.jj 2014-01-03 11:40:57.000000000 +0100 +++ gcc/cselib.h 2014-03-03 19:23:48.633335911 +0100 @@ -95,6 +95,7 @@ extern unsigned int cselib_get_next_uid extern void cselib_preserve_value (cselib_val *); extern bool cselib_preserved_value_p (cselib_val *); extern void cselib_preserve_only_values (void); +extern void cselib_remove_useless_values (vec); extern void cselib_preserve_cfa_base_value (cselib_val *, unsigned int); extern void cselib_add_permanent_equiv (cselib_val *, rtx, rtx); extern bool cselib_have_permanent_equivalences (void); --- gcc/var-tracking.c.jj 2014-03-03 18:28:18.000000000 +0100 +++ gcc/var-tracking.c 2014-03-03 19:27:07.518208397 +0100 @@ -10149,6 +10149,8 @@ vt_initialize (void) } } + if (MAY_HAVE_DEBUG_INSNS) + cselib_remove_useless_values (preserved_values); hard_frame_pointer_adjustment = -1; VTI (ENTRY_BLOCK_PTR_FOR_FN (cfun))->flooded = true; cfa_base_rtx = NULL_RTX; --- gcc/cselib.c.jj 2014-03-03 18:28:18.000000000 +0100 +++ gcc/cselib.c 2014-03-03 19:28:19.832782951 +0100 @@ -200,6 +200,7 @@ static unsigned int cselib_nregs; values. */ static int n_useless_values; static int n_useless_debug_values; +static int n_dropped_useless_values; /* Count values whose locs have been taken exclusively from debug insns for the entire life of the value. */ @@ -546,7 +547,11 @@ cselib_reset_table (unsigned int num) } if (cselib_preserve_constants) - cselib_hash_table.traverse (NULL); + { + n_dropped_useless_values += n_useless_values; + cselib_hash_table.traverse (NULL); + } else { cselib_hash_table.empty (); @@ -681,14 +686,6 @@ remove_useless_values (void) { cselib_val **p, *v; - if (n_useless_values <= MAX_USELESS_VALUES - /* remove_useless_values is linear in the hash table size. Avoid - quadratic behavior for very large hashtables with very few - useless elements. */ - || ((unsigned int)n_useless_values - <= (cselib_hash_table.elements () - n_debug_values) / 4)) - return; - /* First pass: eliminate locations that reference the value. That in turn can make more values useless. */ do @@ -712,6 +709,7 @@ remove_useless_values (void) n_useless_values += n_useless_debug_values; n_debug_values -= n_useless_debug_values; n_useless_debug_values = 0; + n_dropped_useless_values = 0; cselib_hash_table.traverse (NULL); @@ -763,11 +761,43 @@ cselib_preserve_only_values (void) cselib_invalidate_mem (callmem); - remove_useless_values (); + if ((n_dropped_useless_values + n_useless_values) > MAX_USELESS_VALUES + /* Traversal with discard_useless_locs is linear in the hash table + size. Avoid quadratic behavior for very large hashtables with + very few useless elements. */ + && ((unsigned int) (n_dropped_useless_values + n_useless_values) + > (cselib_hash_table.elements () - n_debug_values) / 4)) + { + /* Eliminate locations that reference the value. That in + turn can make more values useless. */ + do + { + values_became_useless = 0; + cselib_hash_table.traverse (NULL); + } + while (values_became_useless); + n_dropped_useless_values = 0; + } gcc_assert (first_containing_mem == &dummy_val); } +/* Clean out useless values (i.e. those which no longer have locations + associated with them) from both hash tables. */ + +void +cselib_remove_useless_values (vec values) +{ + unsigned int i; + rtx val; + + if (n_dropped_useless_values) + remove_useless_values (); + cselib_preserved_hash_table.traverse (NULL); + FOR_EACH_VEC_ELT (values, i, val) + discard_useless_locs (&CSELIB_VAL_PTR (val), NULL); +} + /* Arrange for a value to be marked as based on stack pointer for find_base_term purposes. */ @@ -2720,7 +2750,13 @@ cselib_process_insn (rtx insn) cselib_current_insn = NULL_RTX; - remove_useless_values (); + if (n_useless_values > MAX_USELESS_VALUES + /* remove_useless_values is linear in the hash table size. Avoid + quadratic behavior for very large hashtables with very few + useless elements. */ + && ((unsigned int)n_useless_values + > (cselib_hash_table.elements () - n_debug_values) / 4)) + remove_useless_values (); } /* Initialize cselib for one pass. The caller must also call @@ -2790,6 +2826,7 @@ cselib_finish (void) n_useless_values = 0; n_useless_debug_values = 0; n_debug_values = 0; + n_dropped_useless_values = 0; next_uid = 0; }