From patchwork Tue Jan 7 11:59:09 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kugan Vivekanandarajah X-Patchwork-Id: 22910 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pa0-f70.google.com (mail-pa0-f70.google.com [209.85.220.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 998D5216D9 for ; Tue, 7 Jan 2014 11:59:20 +0000 (UTC) Received: by mail-pa0-f70.google.com with SMTP id fa1sf720422pad.1 for ; Tue, 07 Jan 2014 03:59:19 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:message-id:date:from:user-agent :mime-version:to:cc:subject:references:in-reply-to:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe:content-type; bh=aYkaS4iWW08IThzrEZQTxhWCcDce7YsC/zNDSFm8aWY=; b=iJqdTUS+YmB9CNkTfyODock6zF7hUWUKkgoNZObI2Z6IoET8i00xos9MOXw3JNz5RO h1g/rzgc2mr9cwXoX2r+KNweU+qEFnPPPHMpxr2CvLaYDL11H5xAhofhRq0S2uhqE6Fj QSI2UKkwT/axFfSad3wFr1vdTRJLzdzK1YzL9nSKWatbnLacRsAngpRbmdKqWMkc0joK XUHZFN73+yUYj/vh5YAloDwLA1alCCJb8vugRbK0mHvJUO9Qpf7iMehn+36lfBb00dAy Ojf9HInmWMHszKP5dQIQ1UL/8HXLO/RjmHXYn9CnkPEW9ufXjFly4zSx3P8yWh5eCFMo Bnrw== X-Gm-Message-State: ALoCoQlWRzjKbCR9CjjK1EHjXp5MedirKcDhc7Hd6Z73VeOnIyI+TCzDlTWp95593yGirvFXQTyf X-Received: by 10.67.14.70 with SMTP id fe6mr1713540pad.15.1389095959047; Tue, 07 Jan 2014 03:59:19 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.36.161 with SMTP id r1ls84840qej.71.gmail; Tue, 07 Jan 2014 03:59:18 -0800 (PST) X-Received: by 10.58.201.169 with SMTP id kb9mr1361817vec.42.1389095958845; Tue, 07 Jan 2014 03:59:18 -0800 (PST) Received: from mail-vb0-f50.google.com (mail-vb0-f50.google.com [209.85.212.50]) by mx.google.com with ESMTPS id xw5si33444301vec.84.2014.01.07.03.59.18 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 07 Jan 2014 03:59:18 -0800 (PST) Received-SPF: neutral (google.com: 209.85.212.50 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.212.50; Received: by mail-vb0-f50.google.com with SMTP id w18so23839vbj.37 for ; Tue, 07 Jan 2014 03:59:18 -0800 (PST) X-Received: by 10.58.181.71 with SMTP id du7mr1712154vec.25.1389095958735; Tue, 07 Jan 2014 03:59:18 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.59.13.131 with SMTP id ey3csp153954ved; Tue, 7 Jan 2014 03:59:17 -0800 (PST) X-Received: by 10.66.159.132 with SMTP id xc4mr4714656pab.27.1389095956906; Tue, 07 Jan 2014 03:59:16 -0800 (PST) Received: from mail-pb0-f45.google.com (mail-pb0-f45.google.com [209.85.160.45]) by mx.google.com with ESMTPS id t6si31415481pbg.185.2014.01.07.03.59.16 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 07 Jan 2014 03:59:16 -0800 (PST) Received-SPF: neutral (google.com: 209.85.160.45 is neither permitted nor denied by best guess record for domain of kugan.vivekanandarajah@linaro.org) client-ip=209.85.160.45; Received: by mail-pb0-f45.google.com with SMTP id rp16so41467pbb.4 for ; Tue, 07 Jan 2014 03:59:16 -0800 (PST) X-Received: by 10.66.250.202 with SMTP id ze10mr4806678pac.153.1389095956485; Tue, 07 Jan 2014 03:59:16 -0800 (PST) Received: from [192.168.0.100] ([123.208.220.178]) by mx.google.com with ESMTPSA id vn10sm135622258pbc.21.2014.01.07.03.59.13 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 07 Jan 2014 03:59:15 -0800 (PST) Message-ID: <52CBEC0D.4070706@linaro.org> Date: Tue, 07 Jan 2014 22:59:09 +1100 From: Kugan User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.1.0 MIME-Version: 1.0 To: Richard Biener CC: Eric Botcazou , gcc-patches@gcc.gnu.org, "patches@linaro.org" Subject: Re: [PING^2][PATCH][2 of 2] RTL expansion for zero sign extension elimination with VRP References: <51ABFC6E.30205@linaro.org> <1726629.C2vZH2NXuZ@polaris> <520B31F5.7020200@linaro.org> <52245B58.6090507@linaro.org> <5253B4FA.9090203@linaro.org> <525D153A.1030808@linaro.org> <525DDC09.9090509@linaro.org> <526761C7.1060007@linaro.org> <52A15162.40302@linaro.org> In-Reply-To: <52A15162.40302@linaro.org> X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: kugan.vivekanandarajah@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.212.50 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , ping ? I have reorganised the last patch and now handling only VIEW_CONVERT_EXPR, CONVERT_EXPR and NOP_EXPR. Once it is reviewed and necessary changes are made, I will address the other cases as a separate patch (when it reaches that stage). Thanks, Kugan gcc/ +2014-01-07 Kugan Vivekanandarajah + + * dojump.c (do_compare_and_jump): Generate rtl without + zero/sign extension if redundant. + * cfgexpand.c (expand_gimple_stmt_1): Likewise. + (is_assigned_exp_fit_type) : New function. + * cfgexpand.h (is_assigned_exp_fit_type) : Declare. + diff --git a/gcc/cfgexpand.c b/gcc/cfgexpand.c index 7a93975..b2e2f90 100644 --- a/gcc/cfgexpand.c +++ b/gcc/cfgexpand.c @@ -476,6 +476,66 @@ add_scope_conflicts_1 (basic_block bb, bitmap work, bool for_conflict) } } + +/* Check gimple assign stmt and see if zero/sign extension is + redundant. i.e. if an assignment gimple statement has RHS expression + value that can fit in LHS type, subreg and extension to fit can be + redundant. Zero/sign extensions in this case can be removed. */ + +bool +is_assigned_exp_fit_type (tree lhs) +{ + double_int type_min, type_max; + double_int min1, max1; + enum tree_code stmt_code; + tree rhs1; + gimple stmt = SSA_NAME_DEF_STMT (lhs); + + if (gimple_code (stmt) != GIMPLE_ASSIGN) + return false; + + /* We remove extension for non-pointer and integral stmts. */ + if (!INTEGRAL_TYPE_P (TREE_TYPE (lhs)) + || POINTER_TYPE_P (TREE_TYPE (lhs))) + return false; + + stmt_code = gimple_assign_rhs_code (stmt); + rhs1 = gimple_assign_rhs1 (stmt); + type_max = tree_to_double_int (TYPE_MAX_VALUE (TREE_TYPE (lhs))); + type_min = tree_to_double_int (TYPE_MIN_VALUE (TREE_TYPE (lhs))); + + if (TREE_CODE_CLASS (stmt_code) == tcc_unary) + { + bool uns = TYPE_UNSIGNED (TREE_TYPE (rhs1)); + /* Get the value range. */ + if (TREE_CODE (rhs1) == INTEGER_CST) + { + min1 = tree_to_double_int (rhs1); + max1 = tree_to_double_int (rhs1); + } + else if (get_range_info (rhs1, &min1, &max1) != VR_RANGE) + return false; + + switch (stmt_code) + { + case VIEW_CONVERT_EXPR: + case CONVERT_EXPR: + case NOP_EXPR: + /* If rhs value range fits lhs type, zero/sign extension is + redundant. */ + if (max1.cmp (type_max, 0) != 1 + && (type_min.cmp (min1, 0)) != 1) + return true; + else + return false; + default: + return false; + } + } + + return false; +} + /* Generate stack partition conflicts between all partitions that are simultaneously live. */ @@ -3247,6 +3307,20 @@ expand_gimple_stmt_1 (gimple stmt) if (temp == target) ; + /* If the value in SUBREG of temp fits that SUBREG (does not + overflow) and is assigned to target SUBREG of the same mode + without sign conversion, we can skip the SUBREG + and extension. */ + else if (promoted + && is_assigned_exp_fit_type (lhs) + && (GET_CODE (temp) == SUBREG) + && (GET_MODE_PRECISION (GET_MODE (SUBREG_REG (temp))) + >= GET_MODE_PRECISION (GET_MODE (target))) + && (GET_MODE (SUBREG_REG (target)) + == GET_MODE (SUBREG_REG (temp)))) + { + emit_move_insn (SUBREG_REG (target), SUBREG_REG (temp)); + } else if (promoted) { int unsignedp = SUBREG_PROMOTED_UNSIGNED_P (target); diff --git a/gcc/cfgexpand.h b/gcc/cfgexpand.h index 04517a3..c7d73e8 100644 --- a/gcc/cfgexpand.h +++ b/gcc/cfgexpand.h @@ -22,5 +22,6 @@ along with GCC; see the file COPYING3. If not see extern tree gimple_assign_rhs_to_tree (gimple); extern HOST_WIDE_INT estimated_stack_frame_size (struct cgraph_node *); +extern bool is_assigned_exp_fit_type (tree lhs); #endif /* GCC_CFGEXPAND_H */ diff --git a/gcc/dojump.c b/gcc/dojump.c index 73df6d1..73a4b6b 100644 --- a/gcc/dojump.c +++ b/gcc/dojump.c @@ -35,6 +35,7 @@ along with GCC; see the file COPYING3. If not see #include "ggc.h" #include "basic-block.h" #include "tm_p.h" +#include "cfgexpand.h" static bool prefer_and_bit_test (enum machine_mode, int); static void do_jump_by_parts_greater (tree, tree, int, rtx, rtx, int); @@ -1166,6 +1167,62 @@ do_compare_and_jump (tree treeop0, tree treeop1, enum rtx_code signed_code, type = TREE_TYPE (treeop0); mode = TYPE_MODE (type); + + /* Is zero/sign extension redundant. */ + bool op0_ext_redundant = false; + bool op1_ext_redundant = false; + + /* If promoted and the value in SUBREG of op0 fits (does not overflow), + it is a candidate for extension elimination. */ + if (GET_CODE (op0) == SUBREG && SUBREG_PROMOTED_VAR_P (op0)) + op0_ext_redundant = is_assigned_exp_fit_type (treeop0); + + /* If promoted and the value in SUBREG of op1 fits (does not overflow), + it is a candidate for extension elimination. */ + if (GET_CODE (op1) == SUBREG && SUBREG_PROMOTED_VAR_P (op1)) + op1_ext_redundant = is_assigned_exp_fit_type (treeop1); + + /* If zero/sign extension is redundant, generate RTL + for operands without zero/sign extension. */ + if ((op0_ext_redundant || TREE_CODE (treeop0) == INTEGER_CST) + && (op1_ext_redundant || TREE_CODE (treeop1) == INTEGER_CST)) + { + if ((TREE_CODE (treeop1) == INTEGER_CST) + && (!mode_signbit_p (GET_MODE (op1), op1))) + { + /* First operand is constant and signbit is not set (not + represented in RTL as a negative constant). */ + rtx new_op0 = gen_reg_rtx (GET_MODE (SUBREG_REG (op0))); + emit_move_insn (new_op0, SUBREG_REG (op0)); + op0 = new_op0; + } + else if ((TREE_CODE (treeop0) == INTEGER_CST) + && (!mode_signbit_p (GET_MODE (op0), op0))) + { + /* Other operand is constant and signbit is not set (not + represented in RTL as a negative constant). */ + rtx new_op1 = gen_reg_rtx (GET_MODE (SUBREG_REG (op1))); + + emit_move_insn (new_op1, SUBREG_REG (op1)); + op1 = new_op1; + } + else if ((TREE_CODE (treeop0) != INTEGER_CST) + && (TREE_CODE (treeop1) != INTEGER_CST) + && (GET_MODE (op0) == GET_MODE (op1)) + && (GET_MODE (SUBREG_REG (op0)) == GET_MODE (SUBREG_REG (op1)))) + { + /* If both comapre registers fits SUBREG and of the + same mode. */ + rtx new_op0 = gen_reg_rtx (GET_MODE (SUBREG_REG (op0))); + rtx new_op1 = gen_reg_rtx (GET_MODE (SUBREG_REG (op1))); + + emit_move_insn (new_op0, SUBREG_REG (op0)); + emit_move_insn (new_op1, SUBREG_REG (op1)); + op0 = new_op0; + op1 = new_op1; + } + } + if (TREE_CODE (treeop0) == INTEGER_CST && (TREE_CODE (treeop1) != INTEGER_CST || (GET_MODE_BITSIZE (mode)