From patchwork Thu Oct 29 19:18:17 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Lawrence X-Patchwork-Id: 537983 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 A9C1D1402DD for ; Fri, 30 Oct 2015 06:20:56 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=GetbrJmf; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:subject:date:message-id:in-reply-to:references:content-type :content-transfer-encoding; q=dns; s=default; b=I2FOtH9EbhUKU2+y djmECgetFXmsJxUGmYM3quzkmh+gv46su/mDDP+U+EZozQTf52ZdtH3f248f9Axs tzjzgizG3j9Kk1bu1Gr0IIC9T5gTCaiIKpeIhcybA/YouBEqR5A5Ui6qehmbrGbZ qShM+bJF/xqoKfDYL5VsA5yTPMc= 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:from :to:subject:date:message-id:in-reply-to:references:content-type :content-transfer-encoding; s=default; bh=Fmo9IMoZGmfFv4T8MlA630 9OR0U=; b=GetbrJmfHLbLwPWzj6p7Q3LTXna3Fp22XOaAqQng7oDEMoJoFO44/V U3pzRz2WL1XKUTUSWPOiiN2lii04A1MOqztGdn9ZlfXJSuForfDqaLr2nDlpG+3y 7TXbJ0DtvN+JEOACvffgr7CbTpxU2d63xlIovyV3/Hxb0Z0yLxKZ8= Received: (qmail 104740 invoked by alias); 29 Oct 2015 19:20:48 -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 104713 invoked by uid 89); 29 Oct 2015 19:20:48 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.7 required=5.0 tests=AWL, BAYES_00, SPF_PASS autolearn=ham version=3.3.2 X-HELO: eu-smtp-delivery-143.mimecast.com Received: from eu-smtp-delivery-143.mimecast.com (HELO eu-smtp-delivery-143.mimecast.com) (146.101.78.143) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 29 Oct 2015 19:20:46 +0000 Received: from cam-owa1.Emea.Arm.com (fw-tnat.cambridge.arm.com [217.140.96.140]) by eu-smtp-1.mimecast.com with ESMTP id uk-mta-7-534DH9RlQLStieDsoxx1wQ-3; Thu, 29 Oct 2015 19:20:42 +0000 Received: from arm.com ([10.1.2.79]) by cam-owa1.Emea.Arm.com with Microsoft SMTPSVC(6.0.3790.3959); Thu, 29 Oct 2015 19:20:41 +0000 From: Alan Lawrence To: gcc-patches@gcc.gnu.org Subject: [PATCH 1/6]tree-ssa-dom.c: Normalize exprs, starting with ARRAY_REF to MEM_REF Date: Thu, 29 Oct 2015 19:18:17 +0000 Message-Id: <1446146302-17002-2-git-send-email-alan.lawrence@arm.com> In-Reply-To: <1446146302-17002-1-git-send-email-alan.lawrence@arm.com> References: <1446146302-17002-1-git-send-email-alan.lawrence@arm.com> X-MC-Unique: 534DH9RlQLStieDsoxx1wQ-3 X-IsSubscribed: yes This patch just teaches DOM that ARRAY_REFs can be equivalent to MEM_REFs (with pointer type to the array element type). gcc/ChangeLog: * tree-ssa-dom.c (dom_normalize_single_rhs): New. (dom_normalize_gimple_stmt): New. (lookup_avail_expr): Call dom_normalize_gimple_stmt. --- gcc/tree-ssa-dom.c | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 67 insertions(+), 1 deletion(-) diff --git a/gcc/tree-ssa-dom.c b/gcc/tree-ssa-dom.c index 38cceff..fca8a80 100644 --- a/gcc/tree-ssa-dom.c +++ b/gcc/tree-ssa-dom.c @@ -1897,6 +1897,72 @@ vuse_eq (ao_ref *, tree vuse1, unsigned int cnt, void *data) return NULL; } +/* Return the normal form of EXPR, the gimple_assign_rhs1 of a GIMPLE_SINGLE_RHS + assignment, or NULL_TREE if EXPR is already in normal form. + The normal form is such that if two expressions normalize to trees that are + operand_equal_p, then dominator optimizations can replace one by the value + produced by the other. + It is not necessary that expressions with equal canonical forms are + equivalent in all other situations, e.g. aliasing. */ + +static tree +dom_normalize_single_rhs (tree expr) +{ + switch (TREE_CODE (expr)) + { + case ARRAY_REF: + { + tree index = TREE_OPERAND (expr, 1); + tree low_bound = array_ref_low_bound (expr); + if (!TREE_CONSTANT (index) || !TREE_CONSTANT (low_bound)) + return NULL_TREE; + + if (! integer_zerop (low_bound)) + index = fold_build2 (MINUS_EXPR, TREE_TYPE (index), index, low_bound); + + tree esz = array_ref_element_size (expr); + gcc_assert (TREE_CONSTANT (esz)); + tree offset = fold_build2 (MULT_EXPR, sizetype, index, esz); + + offset = fold_convert (build_pointer_type (TREE_TYPE (expr)), offset); + + tree base = TREE_OPERAND (expr, 0); + base = build_fold_addr_expr (base); + + return fold_build2 (MEM_REF, TREE_TYPE (expr), base, offset); + } + default: + return NULL_TREE; + } +} + +/* Return the normal form of STMT, or STMT if it is already normalized. */ + +static gimple * +dom_normalize_gimple_stmt (gimple *stmt) +{ + if (gimple_code (stmt) == GIMPLE_ASSIGN) + { + enum tree_code rhs_code = gimple_assign_rhs_code (stmt); + if (get_gimple_rhs_class (rhs_code) == GIMPLE_SINGLE_RHS) + if (tree nrhs = dom_normalize_single_rhs (gimple_assign_rhs1 (stmt))) + { + tree lhs = gimple_assign_lhs (stmt); + /* Exchanged statements, which are never part of the CFG, + can have invalid LHS. */ + gimple *defstmt = 0; + if (TREE_CODE (lhs) == SSA_NAME) + defstmt = SSA_NAME_DEF_STMT (lhs); + gassign *new_stmt = gimple_build_assign (lhs, nrhs); + if (TREE_CODE (lhs) == SSA_NAME) + SSA_NAME_DEF_STMT (lhs) = defstmt; + gimple_set_vuse (new_stmt, gimple_vuse (stmt)); + return new_stmt; + } + } + return stmt; +} + /* Search for an existing instance of STMT in the AVAIL_EXPRS_STACK table. If found, return its LHS. Otherwise insert STMT in the table and return NULL_TREE. @@ -1918,7 +1984,7 @@ lookup_avail_expr (gimple *stmt, bool insert, else lhs = gimple_get_lhs (stmt); - class expr_hash_elt element (stmt, lhs); + class expr_hash_elt element (dom_normalize_gimple_stmt (stmt), lhs); if (dump_file && (dump_flags & TDF_DETAILS)) {