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: Richard Biener <richard dot guenther at gmail dot com>
- To: Kugan <kugan dot vivekanandarajah at linaro dot org>
- 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: Fri, 11 Jul 2014 14:47:31 +0200
- 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>
On Fri, Jul 11, 2014 at 1:52 PM, Kugan
<kugan.vivekanandarajah@linaro.org> wrote:
> Thanks foe the review and suggestions.
>
> On 10/07/14 22:15, Richard Biener wrote:
>> On Mon, Jul 7, 2014 at 8:55 AM, Kugan <kugan.vivekanandarajah@linaro.org> wrote:
>
> [...]
>
>>>
>>> For -fwrapv, it is due to how PROMOTE_MODE is defined in arm back-end.
>>> In the test-case, a function (which has signed char return type) returns
>>> -1 in one of the paths. ARM PROMOTE_MODE changes that to 255 and relies
>>> on zero/sign extension generated by RTL again for the correct value. I
>>> saw some other targets also defining similar think. I am therefore
>>> skipping removing zero/sign extension if the ssa variable can be set to
>>> negative integer constants.
>>
>> Hm? I think you should rather check that you are removing a
>> sign-/zero-extension - PROMOTE_MODE tells you if it will sign- or
>> zero-extend. Definitely
>>
>> + /* In some architectures, negative integer constants are truncated and
>> + sign changed with target defined PROMOTE_MODE macro. This will impact
>> + the value range seen here and produce wrong code if zero/sign extensions
>> + are eliminated. Therefore, return false if this SSA can have negative
>> + integers. */
>> + if (is_gimple_assign (stmt)
>> + && (TREE_CODE_CLASS (gimple_assign_rhs_code (stmt)) == tcc_unary))
>> + {
>> + tree rhs1 = gimple_assign_rhs1 (stmt);
>> + if (TREE_CODE (rhs1) == INTEGER_CST
>> + && !TYPE_UNSIGNED (TREE_TYPE (ssa))
>> + && tree_int_cst_compare (rhs1, integer_zero_node) == -1)
>> + return false;
>>
>> looks completely bogus ... (an unary op with a constant operand?)
>> instead you want to do sth like
>
> I see that unary op with a constant operand is not possible in gimple.
> What I wanted to check here is any sort of constant loads; but seems
> that will not happen in gimple. Is PHI statements the only possible
> statements where we will end up with such constants.
No, in theory you can have
ssa_1 = -1;
but that's not unary but a GIMPLE_SINGLE_RHS and thus
gimple_assign_rhs_code (stmt) == INTEGER_CST.
>> mode = TYPE_MODE (TREE_TYPE (ssa));
>> rhs_uns = TYPE_UNSIGNED (TREE_TYPE (ssa));
>> PROMOTE_MODE (mode, rhs_uns, TREE_TYPE (ssa));
>>
>> instead of initializing rhs_uns from ssas type. That is, if
>> PROMOTE_MODE tells you to promote _not_ according to ssas sign then
>> honor that.
>
> This is triggered in pr43017.c in function foo for arm-none-linux-gnueabi.
>
> where, the gimple statement that cause this looks like:
> .....
> # _3 = PHI <_17(7), -1(2)>
> bb43:
> return _3;
>
> ARM PROMOTE_MODE changes the sign for integer constants only and hence
> looking at the variable with PROMOTE_MODE is not changing the sign in
> this case.
>
> #define PROMOTE_MODE(MODE, UNSIGNEDP, TYPE) \
> if (GET_MODE_CLASS (MODE) == MODE_INT \
> && GET_MODE_SIZE (MODE) < 4) \
> { \
> if (MODE == QImode) \
> UNSIGNEDP = 1; \
> else if (MODE == HImode) \
> UNSIGNEDP = 1; \
> (MODE) = SImode; \
> }
Where does it only apply for "constants"? It applies to all QImode and
HImode entities.
>>> As for the -fno-strict-overflow case, if the variables overflows, in VRP
>>> dumps, I see +INF(OVF), but the value range stored in ssa has TYPE_MAX.
>>> We therefore should limit the comparison to (TYPE_MIN < VR_MIN && VR_MAX
>>> < TYPE_MAX) instead of (TYPE_MIN <= VR_MIN && VR_MAX <= TYPE_MAX) when
>>> checking to be sure that this is not the overflowing case. Attached
>>> patch changes this.
>>
>> I don't think that's necessary - the overflow cases happen only when
>> that overflow has undefined behavior, thus any valid program will have
>> values <= MAX.
>
> I see that you have now removed +INF(OVF). I will change it this way.
I have not removed anything, I just fixed a bug.
Richard.
> Thanks again,
> Kugan
>