From patchwork Wed Jun 25 08:14:57 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kugan Vivekanandarajah X-Patchwork-Id: 32454 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ig0-f197.google.com (mail-ig0-f197.google.com [209.85.213.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 6BC5920C88 for ; Wed, 25 Jun 2014 08:15:26 +0000 (UTC) Received: by mail-ig0-f197.google.com with SMTP id r10sf4859888igi.4 for ; Wed, 25 Jun 2014 01:15:25 -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:cc :subject:references:in-reply-to:x-original-sender :x-original-authentication-results:content-type; bh=D+5si9TuyIoJIFwbUIWPAIZOMAvkDQHeylz+tBq+csA=; b=ZTlUBxJuIY7WJSk0ok6I9zqyLua9m71xLaDw7uh1Qg04S0AN1IRUouZ9e/Nxtn6Qis aPmCOC4KJdlgIpHdJDn7Vo9VYf4GLR+K3MdSbV3JzRSLI7Q01axnM1KiCP82Jj5vwRr0 jVsZXzxmWTak/qSQO9BT9klxi/c8PCUmiTr68565xHl5ZK7ZQzzkDhEzRhQQJ+FAwQXr rInIagsahY3g+r9i9Zgx8HjR3silZGk/gtio9u7CzA3OvMURoAf/Wn44Ht9toZN48Pt6 5x02hf3AjQJAhGZvQ3lkuh4AB7o5fa8VG8U9MKVeMFhW4z4QxIFjWG6YpgL0N5fFkDha RgUg== X-Gm-Message-State: ALoCoQn+FriHpsmq9mxpKqZ04N96oTMfFVUjQYBBMYj6D7zZFcd9TAOm6j6iaxn0yxvEIvEsl/WS X-Received: by 10.50.98.69 with SMTP id eg5mr3940553igb.7.1403684125554; Wed, 25 Jun 2014 01:15:25 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.23.136 with SMTP id 8ls501659qgp.33.gmail; Wed, 25 Jun 2014 01:15:25 -0700 (PDT) X-Received: by 10.220.80.70 with SMTP id s6mr157168vck.44.1403684125478; Wed, 25 Jun 2014 01:15:25 -0700 (PDT) Received: from mail-ve0-x22e.google.com (mail-ve0-x22e.google.com [2607:f8b0:400c:c01::22e]) by mx.google.com with ESMTPS id ha4si1832765veb.1.2014.06.25.01.15.25 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 25 Jun 2014 01:15:25 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2607:f8b0:400c:c01::22e as permitted sender) client-ip=2607:f8b0:400c:c01::22e; Received: by mail-ve0-f174.google.com with SMTP id jx11so1583885veb.5 for ; Wed, 25 Jun 2014 01:15:25 -0700 (PDT) X-Received: by 10.52.191.97 with SMTP id gx1mr2157vdc.55.1403684125379; Wed, 25 Jun 2014 01:15:25 -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 tc5csp270698vcb; Wed, 25 Jun 2014 01:15:24 -0700 (PDT) X-Received: by 10.66.122.135 with SMTP id ls7mr9447709pab.84.1403684124244; Wed, 25 Jun 2014 01:15:24 -0700 (PDT) Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id qz9si4049966pab.152.2014.06.25.01.15.23 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 25 Jun 2014 01:15:24 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-371057-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Received: (qmail 19151 invoked by alias); 25 Jun 2014 08:15:10 -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 19135 invoked by uid 89); 25 Jun 2014 08:15:10 -0000 X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.3 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-pa0-f48.google.com Received: from mail-pa0-f48.google.com (HELO mail-pa0-f48.google.com) (209.85.220.48) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Wed, 25 Jun 2014 08:15:08 +0000 Received: by mail-pa0-f48.google.com with SMTP id et14so1405214pad.7 for ; Wed, 25 Jun 2014 01:15:06 -0700 (PDT) X-Received: by 10.68.167.133 with SMTP id zo5mr8977880pbb.21.1403684106710; Wed, 25 Jun 2014 01:15:06 -0700 (PDT) Received: from [10.1.1.4] (58-6-183-210.dyn.iinet.net.au. [58.6.183.210]) by mx.google.com with ESMTPSA id bx5sm3930728pbd.69.2014.06.25.01.15.00 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 25 Jun 2014 01:15:01 -0700 (PDT) Message-ID: <53AA8501.809@linaro.org> Date: Wed, 25 Jun 2014 18:14:57 +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 CC: "gcc-patches@gcc.gnu.org" Subject: Re: [PATCH 2/2] Enable elimination of zext/sext References: <53A9658F.2070304@linaro.org> <53A966BF.30806@linaro.org> <20140624122101.GX31640@tucnak.redhat.com> In-Reply-To: <20140624122101.GX31640@tucnak.redhat.com> 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:c01::22e 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 On 24/06/14 22:21, Jakub Jelinek wrote: > On Tue, Jun 24, 2014 at 09:53:35PM +1000, Kugan wrote: >> 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. > > Similarly to the other patch, no gcc/ prefix in ChangeLog, no space before > :, watch for too long lines, remove useless ()s around conditions. Changed it. >> +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 > > Why? > >> + || (flag_strict_overflow == false) > > Why? Also, that would be !flag_strict_overflow instead of > (flag_strict_overflow == false) For these flags, value ranges generated are not usable for extension eliminations. Therefore, without this some of the test cases in regression fails. For example: short a; void foo (void) { for (a = 0; a >= 0; a++) ; } -Os -fno-strict-overflow produces the following range for the index increment and hence goes into infinite loop. _10: [1, 32768] _10 = _4 + 1; > >> + || (ssa == NULL_TREE) >> + || (TREE_CODE (ssa) != SSA_NAME) >> + || !INTEGRAL_TYPE_P (TREE_TYPE (ssa)) >> + || POINTER_TYPE_P (TREE_TYPE (ssa))) > > All pointer types are !INTEGRAL_TYPE_P, so the last condition > doesn't make any sense. I have changed this. Please see the attached patch. Thanks, Kugan gcc/ 2014-06-25 Kugan Vivekanandarajah * 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. * expr.h (is_promoted_for_type): New function definition. * 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 a3e6faa..eac512f 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 f9103a5..15da092 100644 --- a/gcc/expr.c +++ b/gcc/expr.c @@ -9210,6 +9210,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 + || ssa == NULL_TREE + || TREE_CODE (ssa) != SSA_NAME + || !INTEGRAL_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 @@ -9513,7 +9566,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.