From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 18222 invoked by alias); 1 Aug 2014 11:16:20 -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 18057 invoked by uid 89); 1 Aug 2014 11:16:19 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.8 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-wg0-f41.google.com Received: from mail-wg0-f41.google.com (HELO mail-wg0-f41.google.com) (74.125.82.41) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Fri, 01 Aug 2014 11:16:14 +0000 Received: by mail-wg0-f41.google.com with SMTP id z12so4227409wgg.24 for ; Fri, 01 Aug 2014 04:16:12 -0700 (PDT) MIME-Version: 1.0 X-Received: by 10.180.21.208 with SMTP id x16mr5717844wie.73.1406891771921; Fri, 01 Aug 2014 04:16:11 -0700 (PDT) Received: by 10.194.20.69 with HTTP; Fri, 1 Aug 2014 04:16:11 -0700 (PDT) In-Reply-To: <53DB1CE2.3080401@linaro.org> References: <53A9658F.2070304@linaro.org> <53A966BF.30806@linaro.org> <20140624122101.GX31640@tucnak.redhat.com> <53AA8501.809@linaro.org> <20140625083618.GZ31640@tucnak.redhat.com> <53BA4458.30804@linaro.org> <53BFD000.1030909@linaro.org> <53C34734.2080103@linaro.org> <53DB1CE2.3080401@linaro.org> Date: Fri, 01 Aug 2014 11:16:00 -0000 Message-ID: Subject: Re: [PATCH 2/2] Enable elimination of zext/sext From: Richard Biener To: Kugan Cc: Jakub Jelinek , "gcc-patches@gcc.gnu.org" Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-IsSubscribed: yes X-SW-Source: 2014-08/txt/msg00050.txt.bz2 On Fri, Aug 1, 2014 at 6:51 AM, Kugan w= rote: >> + lhs_type =3D lang_hooks.types.type_for_mode (lhs_mode, lhs_uns); >> ... >> + && ((!lhs_uns && !wi::neg_p (min, TYPE_SIGN (lhs_type))) >> ... >> + type_min =3D wide_int::from (TYPE_MIN_VALUE (lhs_type), prec, >> + TYPE_SIGN (TREE_TYPE (ssa))); >> + type_max =3D wide_int::from (TYPE_MAX_VALUE (lhs_type), prec, >> + TYPE_SIGN (TREE_TYPE (ssa))); >> >> you shouldn't try getting at lhs_type. Btw, do you want to constrain >> lhs_mode to MODE_INTs somewhere? > > Is this in addition to !INTEGRAL_TYPE_P (TREE_TYPE (ssa)))? Do you mean > that I should check lhs_mode as well? No, that's probably enough. >> For TYPE_SIGN use lhs_uns instead, for the min/max value you >> should use wi::min_value () and wi::max_value () instead. >> >> You are still using TYPE_SIGN (TREE_TYPE (ssa)) here and later, >> but we computed rhs_uns "properly" using PROMOTE_MODE. >> I think the code with re-setting lhs_uns if rhs_uns !=3D lhs_uns >> and later using TYPE_SIGN again is pretty hard to follow. >> >> Btw, it seems you need to conditionalize the call to PROMOTE_MODE >> on its availability. >> >> Isn't it simply about choosing a proper range we need to restrict >> ssa to? That is, dependent on rhs_uns computed by PROMOTE_MODE, >> simply: >> >> + mode =3D TYPE_MODE (TREE_TYPE (ssa)); >> + rhs_uns =3D TYPE_UNSIGNED (TREE_TYPE (ssa)); >> #ifdef PROMOTE_MODE >> + PROMOTE_MODE (mode, rhs_uns, TREE_TYPE (ssa)); >> #endif >> >> if (rhs_uns) >> return wi::ge_p (min, 0); // if min >=3D 0 then range contains posit= ive values >> else >> return wi::le_p (max, wi::max_value (TYPE_PRECISION (TREE_TYPE >> (ssa)), SIGNED); // if max <=3D signed-max-of-type then range doesn't >> need sign-extension > > I think we will have to check that ssa has necessary sign/zero extension > when assigned to lhs_type. If PROMOTE_MODE tells us that ssa's type will > be interpreted differently, the value range of ssa also will have > corresponding range. In this cases, shouldn=E2=80=99t we have to check f= or > upper and lower limit for both min and max? Hmm? That's exactly what the check is testing... we know that min <=3D max thus if min >=3D 0 then max >=3D 0. zero_extension will never do anything on [0, INF] If max < MAX-SIGNED then sign-extension will not do anything. Ok, sign-extension will do sth for negative values still. So rather if (rhs_uns) return wi::geu_p (min, 0); else return wi::ges_p (min, 0) && wi::les_p (max, wi::max_value (TYPE_PRECISION (TREE_TYPE (ssa)), SIGNED)); ? I don't like the use of int_fits_type_p you propose. Richard. > How about this? > > bool > promoted_for_type_p (tree ssa, enum machine_mode lhs_mode, bool lhs_uns) > { > wide_int min, max; > tree lhs_type, rhs_type; > bool rhs_uns; > enum machine_mode rhs_mode; > tree min_tree, max_tree; > > if (ssa =3D=3D NULL_TREE > || TREE_CODE (ssa) !=3D 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) !=3D VR_RANGE) > return false; > > rhs_uns =3D TYPE_UNSIGNED (TREE_TYPE (ssa)); > if (rhs_uns !=3D lhs_uns) > { > /* Signedness of LHS and RHS differs and values also cannot be > represented in LHS range. */ > unsigned int prec =3D min.get_precision (); > if ((lhs_uns && wi::neg_p (min, rhs_uns ? UNSIGNED : SIGNED)) > || (!lhs_uns && !wi::le_p (max, > wi::max_value (prec, SIGNED), > rhs_uns ? UNSIGNED : SIGNED))) > return false; > } > > /* In some architectures, modes are promoted and sign changed with > target defined PROMOTE_MODE macro. If PROMOTE_MODE tells you to > promote _not_ according to ssa's sign then honour that. */ > rhs_mode =3D TYPE_MODE (TREE_TYPE (ssa)); > #ifdef PROMOTE_MODE > PROMOTE_MODE (rhs_mode, rhs_uns, TREE_TYPE (ssa)); > #endif > > rhs_type =3D lang_hooks.types.type_for_mode (rhs_mode, rhs_uns); > lhs_type =3D lang_hooks.types.type_for_mode (lhs_mode, lhs_uns); > min_tree =3D wide_int_to_tree (rhs_type, min); > max_tree =3D wide_int_to_tree (rhs_type, max); > > /* Check if values lies in-between the type range. */ > if (int_fits_type_p (min_tree, lhs_type) > && int_fits_type_p (max_tree, lhs_type)) > return true; > else > return false; > } > > > Thanks, > Kugan