From patchwork Tue Jun 24 11:53:35 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kugan Vivekanandarajah X-Patchwork-Id: 32419 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-yh0-f72.google.com (mail-yh0-f72.google.com [209.85.213.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 9FFD7201EF for ; Tue, 24 Jun 2014 11:53:57 +0000 (UTC) Received: by mail-yh0-f72.google.com with SMTP id f10sf335294yha.3 for ; Tue, 24 Jun 2014 04:53:57 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:mailing-list:precedence:list-id :list-unsubscribe:list-archive:list-post:list-help:sender :delivered-to:message-id:date:from:user-agent:mime-version:to :subject:references:in-reply-to:x-original-sender :x-original-authentication-results:content-type; bh=+hG9khyiyEq10AxKJiA2bcWjtFCSPGr4BHxM+IfmRCA=; b=JmPQGl80dW1dXKsAAJ2JGsJ+Z3ISep4k5O9lGM4edkYvdNvNGNzUGh5bSvmZPwyxwT ZNejGeFD6VKDceur+ZLm70PLaHy1VSR9aK1BwmiITNStZbtvclgNFLSOuGALVmCR0x7x GmieeXbbzzA8xsxxzgoDubcsrjnChL63jiVP0M+nWDFar44J1GIbJtQVMlvq5um2n1lG cWm6uLo60uleh9ICynU44giNSprpKmYxbSV/xSo0KpdrTnIt1gctEeAMARhjSdyniy0I xJFnxQ7Ra+3+7FmP7s/xFg/pyaano5N30dBn/WfwmqIfsJfmCgw8xsFaHgVzAGHikxA0 O18w== X-Gm-Message-State: ALoCoQlaRqlyxXnOcT1G98K3f78FWW6CtPQs0hX+dmwgWXw+yEq/ztkr+v7MGDevYAjZa6jQmi/G X-Received: by 10.52.121.13 with SMTP id lg13mr226245vdb.8.1403610837331; Tue, 24 Jun 2014 04:53:57 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.108.2 with SMTP id i2ls2384639qgf.78.gmail; Tue, 24 Jun 2014 04:53:57 -0700 (PDT) X-Received: by 10.221.37.1 with SMTP id tc1mr281450vcb.32.1403610837255; Tue, 24 Jun 2014 04:53:57 -0700 (PDT) Received: from mail-vc0-x22a.google.com (mail-vc0-x22a.google.com [2607:f8b0:400c:c03::22a]) by mx.google.com with ESMTPS id h16si20205vcu.61.2014.06.24.04.53.57 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 24 Jun 2014 04:53:57 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2607:f8b0:400c:c03::22a as permitted sender) client-ip=2607:f8b0:400c:c03::22a; Received: by mail-vc0-f170.google.com with SMTP id hy10so163748vcb.15 for ; Tue, 24 Jun 2014 04:53:57 -0700 (PDT) X-Received: by 10.52.138.14 with SMTP id qm14mr169090vdb.49.1403610837160; Tue, 24 Jun 2014 04:53:57 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.221.37.5 with SMTP id tc5csp204280vcb; Tue, 24 Jun 2014 04:53:56 -0700 (PDT) X-Received: by 10.66.100.163 with SMTP id ez3mr470974pab.155.1403610836184; Tue, 24 Jun 2014 04:53:56 -0700 (PDT) Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id cv2si37017pbc.135.2014.06.24.04.53.55 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 24 Jun 2014 04:53:56 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-370965-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Received: (qmail 24079 invoked by alias); 24 Jun 2014 11:53:43 -0000 Mailing-List: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org Precedence: list 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 24066 invoked by uid 89); 24 Jun 2014 11:53:42 -0000 X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.4 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-pb0-f54.google.com Received: from mail-pb0-f54.google.com (HELO mail-pb0-f54.google.com) (209.85.160.54) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Tue, 24 Jun 2014 11:53:41 +0000 Received: by mail-pb0-f54.google.com with SMTP id un15so162873pbc.13 for ; Tue, 24 Jun 2014 04:53:39 -0700 (PDT) X-Received: by 10.68.211.164 with SMTP id nd4mr844467pbc.44.1403610819766; Tue, 24 Jun 2014 04:53:39 -0700 (PDT) Received: from [192.168.0.102] ([1.147.128.138]) by mx.google.com with ESMTPSA id au4sm109552pbc.10.2014.06.24.04.53.37 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 24 Jun 2014 04:53:39 -0700 (PDT) Message-ID: <53A966BF.30806@linaro.org> Date: Tue, 24 Jun 2014 21:53:35 +1000 From: Kugan User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.6.0 MIME-Version: 1.0 To: Jakub Jelinek , "gcc-patches@gcc.gnu.org" Subject: [PATCH 2/2] Enable elimination of zext/sext References: <53A9658F.2070304@linaro.org> In-Reply-To: <53A9658F.2070304@linaro.org> X-IsSubscribed: yes X-Original-Sender: kugan.vivekanandarajah@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2607:f8b0:400c:c03::22a as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org; dkim=pass header.i=@gcc.gnu.org X-Google-Group-Id: 836684582541 Sets proper flags on the SUBREG based on value range info and enables elimination of zext/sext when possible. Thanks, Kugan gcc/ 2014-06-24 Kugan Vivekanandarajah * gcc/calls.c (precompute_arguments: Check is_promoted_for_type and set the promoted mode. (is_promoted_for_type) : New function. (expand_expr_real_1) : Check is_promoted_for_type and set the promoted mode. * gcc/expr.h (is_promoted_for_type) : New function definition. * gcc/cfgexpand.c (expand_gimple_stmt_1) : Call emit_move_insn if SUBREG is promoted with SRP_SIGNED_AND_UNSIGNED. diff --git a/gcc/calls.c b/gcc/calls.c index c1fe3b8..4ef9df8 100644 --- a/gcc/calls.c +++ b/gcc/calls.c @@ -1484,7 +1484,10 @@ precompute_arguments (int num_actuals, struct arg_data *args) args[i].initial_value = gen_lowpart_SUBREG (mode, args[i].value); SUBREG_PROMOTED_VAR_P (args[i].initial_value) = 1; - SUBREG_PROMOTED_SET (args[i].initial_value, args[i].unsignedp); + if (is_promoted_for_type (args[i].tree_value, mode, !args[i].unsignedp)) + SUBREG_PROMOTED_SET (args[i].initial_value, SRP_SIGNED_AND_UNSIGNED); + else + SUBREG_PROMOTED_SET (args[i].initial_value, args[i].unsignedp); } } } diff --git a/gcc/cfgexpand.c b/gcc/cfgexpand.c index e8cd87f..0540b4d 100644 --- a/gcc/cfgexpand.c +++ b/gcc/cfgexpand.c @@ -3309,7 +3309,13 @@ expand_gimple_stmt_1 (gimple stmt) GET_MODE (target), temp, unsignedp); } - convert_move (SUBREG_REG (target), temp, unsignedp); + if ((SUBREG_PROMOTED_GET (target) == SRP_SIGNED_AND_UNSIGNED) + && (GET_CODE (temp) == SUBREG) + && (GET_MODE (target) == GET_MODE (temp)) + && (GET_MODE (SUBREG_REG (target)) == GET_MODE (SUBREG_REG (temp)))) + emit_move_insn (SUBREG_REG (target), SUBREG_REG (temp)); + else + convert_move (SUBREG_REG (target), temp, unsignedp); } else if (nontemporal && emit_storent_insn (target, temp)) ; diff --git a/gcc/expr.c b/gcc/expr.c index a8db9f5..b2c8146 100644 --- a/gcc/expr.c +++ b/gcc/expr.c @@ -9209,6 +9209,59 @@ expand_expr_real_2 (sepops ops, rtx target, enum machine_mode tmode, } #undef REDUCE_BIT_FIELD +/* Return TRUE if value in SSA is already zero/sign extended for lhs type + (type here is the combination of LHS_MODE and LHS_UNS) using value range + information stored. Return FALSE otherwise. */ +bool +is_promoted_for_type (tree ssa, enum machine_mode lhs_mode, bool lhs_uns) +{ + wide_int type_min, type_max; + wide_int min, max, limit; + unsigned int prec; + tree lhs_type; + bool rhs_uns; + + if (flag_wrapv + || (flag_strict_overflow == false) + || (ssa == NULL_TREE) + || (TREE_CODE (ssa) != SSA_NAME) + || !INTEGRAL_TYPE_P (TREE_TYPE (ssa)) + || POINTER_TYPE_P (TREE_TYPE (ssa))) + return false; + + /* Return FALSE if value_range is not recorded for SSA. */ + if (get_range_info (ssa, &min, &max) != VR_RANGE) + return false; + + lhs_type = lang_hooks.types.type_for_mode (lhs_mode, lhs_uns); + rhs_uns = TYPE_UNSIGNED (TREE_TYPE (ssa)); + prec = min.get_precision (); + + /* Signed maximum value. */ + limit = wide_int::from (TYPE_MAX_VALUE (TREE_TYPE (ssa)), prec, SIGNED); + + /* Signedness of LHS and RHS differs but values in range. */ + if ((rhs_uns != lhs_uns) + && ((!lhs_uns && !wi::neg_p (min, TYPE_SIGN (lhs_type))) + || (lhs_uns && (wi::cmp (max, limit, TYPE_SIGN (TREE_TYPE (ssa))) == -1)))) + lhs_uns = !lhs_uns; + + /* Signedness of LHS and RHS should match. */ + if (rhs_uns != lhs_uns) + return false; + + type_min = wide_int::from (TYPE_MIN_VALUE (lhs_type), prec, TYPE_SIGN (TREE_TYPE (ssa))); + type_max = wide_int::from (TYPE_MAX_VALUE (lhs_type), prec, TYPE_SIGN (TREE_TYPE (ssa))); + + /* Check if values lies in-between the type range. */ + if ((wi::neg_p (max, TYPE_SIGN (TREE_TYPE (ssa))) + || (wi::cmp (max, type_max, TYPE_SIGN (TREE_TYPE (ssa))) != 1)) + && (!wi::neg_p (min, TYPE_SIGN (TREE_TYPE (ssa))) + || (wi::cmp (type_min, min, TYPE_SIGN (TREE_TYPE (ssa))) != 1))) + return true; + + return false; +} /* Return TRUE if expression STMT is suitable for replacement. Never consider memory loads as replaceable, because those don't ever lead @@ -9512,7 +9565,10 @@ expand_expr_real_1 (tree exp, rtx target, enum machine_mode tmode, temp = gen_lowpart_SUBREG (mode, decl_rtl); SUBREG_PROMOTED_VAR_P (temp) = 1; - SUBREG_PROMOTED_SET (temp, unsignedp); + if (is_promoted_for_type (ssa_name, mode, !unsignedp)) + SUBREG_PROMOTED_SET (temp, SRP_SIGNED_AND_UNSIGNED); + else + SUBREG_PROMOTED_SET (temp, unsignedp); return temp; } diff --git a/gcc/expr.h b/gcc/expr.h index 6a1d3ab..e99d000 100644 --- a/gcc/expr.h +++ b/gcc/expr.h @@ -440,6 +440,7 @@ extern rtx expand_expr_real_1 (tree, rtx, enum machine_mode, enum expand_modifier, rtx *, bool); extern rtx expand_expr_real_2 (sepops, rtx, enum machine_mode, enum expand_modifier); +extern bool is_promoted_for_type (tree, enum machine_mode, bool); /* Generate code for computing expression EXP. An rtx for the computed value is returned. The value is never null.