From patchwork Thu Apr 4 14:12:18 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yuri Rumyantsev X-Patchwork-Id: 233836 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 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "localhost", Issuer "www.qmailtoaster.com" (not verified)) by ozlabs.org (Postfix) with ESMTPS id AF80F2C00A8 for ; Fri, 5 Apr 2013 01:12: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 :mime-version:in-reply-to:references:date:message-id:subject :from:to:content-type; q=dns; s=default; b=mwiONJ5tX8K0gp98uDFSw 7HHnQvMZhR4sTOMm5LhVdr/jwoHQhbXaMoAA1+d/O/rqgXlWdWPjyhtYGP2GEGxW 3XJBkGaH/Lv9k1W1R4/zVTw5UOD0BGgrIB+HtOZet5JkZv1aGc07lch8aVSGy4wM GjihK33uSQSe9E+5iLn0/g= 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 :mime-version:in-reply-to:references:date:message-id:subject :from:to:content-type; s=default; bh=+bAmtgguK7w6YUiLiFPsAYvzJ3g =; b=v1G51rp7jeDTdChP3ZsLhG53S8rOT6SSVubYOy42oxukeOgsHIq4pzJ1qjK RRqIa2ce8dzDl33oirqrGZ8AxukhPKDo73Gvq3NfpfGEpbJmUmEWzbydiTasudkS hv4N70JdRDdvj3gUjn1rx/U1RuVcWd0QGqn1PWc7E95kfP3s= Received: (qmail 6054 invoked by alias); 4 Apr 2013 14:12:26 -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 6042 invoked by uid 89); 4 Apr 2013 14:12:26 -0000 X-Spam-SWARE-Status: No, score=-5.7 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, KHOP_RCVD_TRUST, KHOP_THREADED, RCVD_IN_DNSWL_LOW, RCVD_IN_HOSTKARMA_YE autolearn=ham version=3.3.1 Received: from mail-wi0-f177.google.com (HELO mail-wi0-f177.google.com) (209.85.212.177) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Thu, 04 Apr 2013 14:12:23 +0000 Received: by mail-wi0-f177.google.com with SMTP id hm14so2643179wib.10 for ; Thu, 04 Apr 2013 07:12:21 -0700 (PDT) MIME-Version: 1.0 X-Received: by 10.180.82.68 with SMTP id g4mr9386650wiy.26.1365084738971; Thu, 04 Apr 2013 07:12:18 -0700 (PDT) Received: by 10.216.203.5 with HTTP; Thu, 4 Apr 2013 07:12:18 -0700 (PDT) In-Reply-To: References: <0EFAB2BDD0F67E4FB6CCC8B9F87D7569160DFB90@IRSMSX101.ger.corp.intel.com> Date: Thu, 4 Apr 2013 18:12:18 +0400 Message-ID: Subject: Re: FW: [PATCH] Avoid a few find_base_term calls in alias.c From: Yuri Rumyantsev To: gcc-patches , Richard Biener , Igor Zamyatin Hi Richard, You slightly change behavior of find_base_term, namely before your fix we have the following code: if (REG_P (tmp1) && REG_POINTER (tmp1)) { rtx base = find_base_term (tmp1); if (base) return base; } but in your fix you added the following checks on base: tmp1 = find_base_term (tmp1); if (tmp1 != NULL_RTX && ((REG_P (tmp1) && REG_POINTER (tmp1)) || known_base_value_p (tmp1))) return tmp1; Why you added these checks since function arguments may not considered as bases. Thanks in advance. Yuri. -----Original Message----- From: gcc-patches-owner@gcc.gnu.org [mailto:gcc-patches-owner@gcc.gnu.org] On Behalf Of Richard Biener Sent: Tuesday, March 26, 2013 4:33 PM To: gcc-patches@gcc.gnu.org Subject: [PATCH] Avoid a few find_base_term calls in alias.c We have already computed the base term for some of the arguments of some calls to base_alias_check. PR39326 shows that find_base_term is very costly called from RTL PRE at -O2 (it mostly recurses through the PLUS/MINUS_EXPR case). The following patch avoids computing find_base_term when not really necessary. Bootstrapped and tested on x86_64-unknown-linux-gnu. Richard. 2013-03-26 Richard Biener * alias.c (find_base_term): Avoid redundant and not used recursion. (base_alias_check): Get the initial base term from the caller. (true_dependence_1): Compute and pass base terms to base_alias_check. (write_dependence_p): Likewise. (may_alias_p): Likewise. -1672,34 +1672,30 @@ find_base_term (rtx x) if (tmp1 == pic_offset_table_rtx && CONSTANT_P (tmp2)) return find_base_term (tmp2); - /* If either operand is known to be a pointer, then use it + /* If either operand is known to be a pointer, then prefer it to determine the base term. */ if (REG_P (tmp1) && REG_POINTER (tmp1)) + ; + else if (REG_P (tmp2) && REG_POINTER (tmp2)) { - rtx base = find_base_term (tmp1); - if (base) - return base; + rtx tem = tmp1; + tmp1 = tmp2; + tmp2 = tem; } - if (REG_P (tmp2) && REG_POINTER (tmp2)) - { - rtx base = find_base_term (tmp2); - if (base) - return base; - } - - /* Neither operand was known to be a pointer. Go ahead and find the - base term for both operands. */ - tmp1 = find_base_term (tmp1); - tmp2 = find_base_term (tmp2); - - /* If either base term is named object or a special address + /* Go ahead and find the base term for both operands. If either base + term is from a pointer or is a named object or a special address (like an argument or stack reference), then use it for the base term. */ - if (tmp1 != 0 && known_base_value_p (tmp1)) + tmp1 = find_base_term (tmp1); + if (tmp1 != NULL_RTX + && ((REG_P (tmp1) && REG_POINTER (tmp1)) + || known_base_value_p (tmp1))) return tmp1; - - if (tmp2 != 0 && known_base_value_p (tmp2)) + tmp2 = find_base_term (tmp2); + if (tmp2 != NULL_RTX + && ((REG_P (tmp2) && REG_POINTER (tmp2)) + || known_base_value_p (tmp2))) return tmp2; /* We could not determine which of the two operands was the @@ -1736,12 +1732,9 @@ may_be_sp_based_p (rtx x) objects, 1 if they might be pointers to the same object. */ static int -base_alias_check (rtx x, rtx y, enum machine_mode x_mode, - enum machine_mode y_mode) +base_alias_check (rtx x, rtx x_base, rtx y, rtx y_base, + enum machine_mode x_mode, enum machine_mode y_mode) { - rtx x_base = find_base_term (x); - rtx y_base = find_base_term (y); - /* If the address itself has no known base see if a known equivalent value has one. If either address still has no known base, nothing is known about aliasing. */ @@ -2511,7 +2504,9 @@ true_dependence_1 (const_rtx mem, enum m && CONSTANT_POOL_ADDRESS_P (base)))) return 0; - if (! base_alias_check (x_addr, mem_addr, GET_MODE (x), mem_mode)) + rtx mem_base = find_base_term (mem_addr); + if (! base_alias_check (x_addr, base, mem_addr, mem_base, + GET_MODE (x), mem_mode)) return 0; x_addr = canon_rtx (x_addr); @@ -2603,16 +2598,16 @@ write_dependence_p (const_rtx mem, const mem_addr = get_addr (mem_addr); } - if (! writep) - { - base = find_base_term (mem_addr); - if (base && (GET_CODE (base) == LABEL_REF - || (GET_CODE (base) == SYMBOL_REF - && CONSTANT_POOL_ADDRESS_P (base)))) - return 0; - } + base = find_base_term (mem_addr); + if (! writep + && base + && (GET_CODE (base) == LABEL_REF + || (GET_CODE (base) == SYMBOL_REF + && CONSTANT_POOL_ADDRESS_P (base)))) + return 0; - if (! base_alias_check (x_addr, mem_addr, GET_MODE (x), + rtx x_base = find_base_term (x_addr); if (! base_alias_check + (x_addr, x_base, mem_addr, base, GET_MODE (x), GET_MODE (mem))) return 0; @@ -2692,7 +2687,10 @@ may_alias_p (const_rtx mem, const_rtx x) mem_addr = get_addr (mem_addr); } - if (! base_alias_check (x_addr, mem_addr, GET_MODE (x), GET_MODE (mem_addr))) + rtx x_base = find_base_term (x_addr); + rtx mem_base = find_base_term (mem_addr); + if (! base_alias_check (x_addr, x_base, mem_addr, mem_base, + GET_MODE (x), GET_MODE (mem_addr))) return 0; x_addr = canon_rtx (x_addr); Index: gcc/alias.c =================================================================== --- gcc/alias.c (revision 197095) +++ gcc/alias.c (working copy) @@ -148,7 +148,7 @@ typedef struct alias_set_entry_d *alias_ static int rtx_equal_for_memref_p (const_rtx, const_rtx); static int memrefs_conflict_p (int, rtx, int, rtx, HOST_WIDE_INT); static void record_set (rtx, const_rtx, void *); -static int base_alias_check (rtx, rtx, enum machine_mode, +static int base_alias_check (rtx, rtx, rtx, rtx, enum machine_mode, enum machine_mode); static rtx find_base_value (rtx); static int mems_in_disjoint_alias_sets_p (const_rtx, const_rtx); @@