This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH 2/2] Enable elimination of zext/sext
- From: Kugan <kugan dot vivekanandarajah at linaro dot org>
- To: Richard Biener <richard dot guenther at gmail dot com>
- Cc: Jakub Jelinek <jakub at redhat dot com>, "gcc-patches at gcc dot gnu dot org" <gcc-patches at gcc dot gnu dot org>
- Date: Sat, 02 Aug 2014 02:03:55 +1000
- Subject: Re: [PATCH 2/2] Enable elimination of zext/sext
- Authentication-results: sourceware.org; auth=none
- References: <53A9658F dot 2070304 at linaro dot org> <53A966BF dot 30806 at linaro dot org> <20140624122101 dot GX31640 at tucnak dot redhat dot com> <53AA8501 dot 809 at linaro dot org> <20140625083618 dot GZ31640 at tucnak dot redhat dot com> <53BA4458 dot 30804 at linaro dot org> <CAFiYyc0qvZhqagfbW6DiWT7TgGWDSw_pT-tgOfX_gn0vdq+p_A at mail dot gmail dot com> <53BFD000 dot 1030909 at linaro dot org> <CAFiYyc0mKoRvHW4B4EXL9Hr0ZLMjjQo7sj0CqSNKFrmCrAgY7Q at mail dot gmail dot com> <53C34734 dot 2080103 at linaro dot org> <CAFiYyc20kV_5yqwzAaFMWU5ZQnATRou2k7uVYNpsZaMzKbX=0g at mail dot gmail dot com> <53DB1CE2 dot 3080401 at linaro dot org> <CAFiYyc2dQxL+iF0Hm=rjmA4BM8t7RNouk4zaq_U7-cUjF=9PsA at mail dot gmail dot com>
>>> if (rhs_uns)
>>> return wi::ge_p (min, 0); // if min >= 0 then range contains positive values
>>> else
>>> return wi::le_p (max, wi::max_value (TYPE_PRECISION (TREE_TYPE
>>> (ssa)), SIGNED); // if max <= 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ât we have to check for
>> upper and lower limit for both min and max?
>
> Hmm? That's exactly what the check is testing... we know that
> min <= max thus if min >= 0 then max >= 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));
>
> ?
Thanks for the explanation. I agree. Donât we have to however check this
on lhs_uns as this function is checking if ssa is promoted for lhs_sign
and lhs_mode?
Here is an attempt based on this. I ran regression testing with
arm-none-linux-gnueabi on qemu-arm without any new regressions.
Sine I am not comparing value ranges to see if it can be represented in
lhs_sigh, I can now skip the PROMOTED_MODE check.
I am still using wide_int::from (instead of wi::max_value) to get the
limit as I have to match the precision with min, max precision.
otherwise wide_int comparisons will not work. Is there a better way for
this?
/* 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
promoted_for_type_p (tree ssa, enum machine_mode lhs_mode, bool lhs_uns)
{
wide_int min, max, limit;
tree lhs_type;
bool rhs_uns;
signop rhs_signop;
if (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;
rhs_uns = TYPE_UNSIGNED (TREE_TYPE (ssa));
rhs_signop = rhs_uns ? UNSIGNED : SIGNED;
lhs_type = lang_hooks.types.type_for_mode (lhs_mode, lhs_uns);
limit = wide_int::from (TYPE_MAX_VALUE (lhs_type),
TYPE_PRECISION (TREE_TYPE (ssa)), SIGNED);
if (lhs_uns)
/* If min >= 0 then range contains positive values and doesnt need
zero-extension. */
return wi::ge_p (min, 0, rhs_signop);
else
/* If min >= 0 and max <= signed-max-of-type then range doesn't need
sign-extension. */
return wi::ge_p (min, 0, rhs_signop) && wi::le_p (max, limit,
rhs_signop);
}
Thanks,
Kugan