From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 19151 invoked by alias); 25 Jun 2014 08:15:10 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 19135 invoked by uid 89); 25 Jun 2014 08:15:10 -0000 Authentication-Results: sourceware.org; auth=none 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-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:message-id:date:from:user-agent:mime-version:to :cc:subject:references:in-reply-to:content-type; bh=D+5si9TuyIoJIFwbUIWPAIZOMAvkDQHeylz+tBq+csA=; b=DwoMigJHceQFgXYTxTi0Z4bmpHYVFnPDmcGxcGz1AUOO2WBfc9t3921HCfn1NlZuLX z/ZkgniS2PQXagJSk/AJLu+aMbfhcVvHviRTZK3Lgbi+3XL8dHvObH/d+qwRCunUifML dIKCZQ6Dl+gTJUf56qClgBLSO/CyAUT6hCMXdTIGldgS7VKuvLxijLEQ9wJ+XnVQ4yzz yqRVRW8YszM2x2807evbMln6iCW1Mok9JXUh2/iU5+qdu/Cgwwxh85Fzh86bPPZuQ6E+ 4D+r1Pbl/xkeT44X/ObgyLPtLE5HQj/0xSn1tILwieL/689nUig64M/9xtWpeQkjgrX7 4TKw== X-Gm-Message-State: ALoCoQkc30kcu6hAxvSs/Pv0DdCjdVH83U2mrKwo3aI6rXN+nCh8E9cC9gp21hB+Xbg5DnHEc6Pc 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 08:15:00 -0000 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> Content-Type: multipart/mixed; boundary="------------040807050708070209020208" X-IsSubscribed: yes X-SW-Source: 2014-06/txt/msg01977.txt.bz2 This is a multi-part message in MIME format. --------------040807050708070209020208 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-length: 2298 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. --------------040807050708070209020208 Content-Type: text/plain; charset=UTF-8; name="p2.txt" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="p2.txt" Content-length: 4582 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. --------------040807050708070209020208--