This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Tree-level fix for PR 69526
- From: "Bin.Cheng" <amker dot cheng at gmail dot com>
- To: Richard Biener <richard dot guenther at gmail dot com>
- Cc: Robin Dapp <rdapp at linux dot vnet dot ibm dot com>, GCC Patches <gcc-patches at gcc dot gnu dot org>
- Date: Thu, 11 May 2017 16:06:03 +0100
- Subject: Re: [PATCH] Tree-level fix for PR 69526
- Authentication-results: sourceware.org; auth=none
- References: <5790A709.4060804@linux.vnet.ibm.com> <CAFiYyc2XVcJA4ZsS5LSLfRD-V3U9tDRpbeU_FRwoNa2w8Z4cGw@mail.gmail.com> <fea2a49d-5f2a-ae24-8601-44e52a2d76b4@linux.vnet.ibm.com> <CAFiYyc2UKpz4krcaxow_=yF6_eFZU_=M5k+6VTHZscDz+g=2uw@mail.gmail.com> <6bc1abab-9b54-fb67-fe98-9aaf993859dd@linux.vnet.ibm.com> <CAFiYyc28DaMGuzcMPZQ+AmHXuuNDAyAorMbW0Vo02EEoyZ+xSg@mail.gmail.com> <aba5346a-027f-ee35-0406-3998ab484621@linux.vnet.ibm.com> <CAFiYyc0aExY-MmRczHKJuQ8UFOpMy_+dzV-n05UJJOhuZVywTg@mail.gmail.com> <CAFiYyc0gnMe7j+DgTeudnpH-zD22nK7Cuv4a2zj4Va-anApTBA@mail.gmail.com> <27be603c-4499-ca96-f252-40934d3e420d@linux.vnet.ibm.com> <CAFiYyc1s699beSC9bpDGxY_2ppenDLoP3nbjYSnThF1cp2YHDA@mail.gmail.com> <d6e24bfd-fc3e-4160-fe27-db3eda5b857c@linux.vnet.ibm.com> <CAFiYyc1AcFG8JzoO3LYW9iyGsPj+7Kv17weZp+U3vTaeiqdhKA@mail.gmail.com> <260c4925-29e2-d50a-871e-397e2f9f4efb@linux.vnet.ibm.com> <CAFiYyc2_WX+3vzX27iRO9byK4zoc8N43F-d=Cg2xXoHwLRTgGQ@mail.gmail.com>
On Tue, Jan 17, 2017 at 9:48 AM, Richard Biener
<richard.guenther@gmail.com> wrote:
> On Tue, Jan 10, 2017 at 2:32 PM, Robin Dapp <rdapp@linux.vnet.ibm.com> wrote:
>> Perhaps I'm still missing how some cases are handled or not handled,
>> sorry for the noise.
>>
>>> I'm not sure there is anything to "interpret" -- the operation is unsigned
>>> and overflow is when the operation may wrap around zero. There might
>>> be clever ways of re-writing the expression to
>>> (uint64_t)((uint32_t)((int32_t)uint32 + -1) + 1)
>>> avoiding the overflow and thus allowing the transform but I'm not sure that's
>>> good.
>>
>> The extra work I introduced was to discern between
>>
>> (uint64_t)(a + UINT_MAX) + 1 -> (uint64_t)(a),
>> (uint64_t)(a + UINT_MAX) + 1 -> (uint64_t)(a) + (uint64_t)(UINT_MAX + 1),
>>
>> For a's range of [1,1] there is an overflow in both cases.
>> We still want to simplify the first case by combining UINT_MAX + 1 -> 0.
>
> So there's the case where a == 0 where (uint64_t)(0 + UINT_MAX) + 1 is not zero.
>
> I think we're still searching for the proper condition on when it is allowed to
> re-write
>
> (uint64_t)(uint32_t + uint32_t-CST) + uint64_t-CST
>
> to
>
> (uint64_t)(uint32_t) + (uint64_t)uint32_t-CST + uint64_t-CST
Hmm, won't (uint32_t + uint32_t-CST) doesn't overflow be sufficient
condition for such transformation?
>
> or to
>
> (uint64_t)(uint32_t) + (uint64_t)(uint32_t-CST + (uint32_t)uint64_t-CST)
We don't actually need to prove this? What complicates this is when
it's safe to transform:
(uint64_t)(uint32_t + uint32_t-CST) + uint64_t-CST
into
(uint64_t)(uint32_t + uint32_t-CSTx)
where
uint32_t-CSTx = uint32_t-CST + (uint32_t)uint64_t-CST
Am I misunderstanding the whole thing?
Thanks,
bin
>
>> If "interpreting" UINT_MAX as -1 is not the correct thing to do, perhaps
>> (uint64_t)((uint32_t)(UINT_MAX + 1)) is? This fails, however, if the
>> outer constant is larger than UINT_MAX. What else can we do here?
>> Do we see cases like the second one at all? If it's not needed, the
>> extra work is likely not needed.
>
> We do have the need to associate and simplfy across conversions but of
> course we have to do it conservatively correct.
>
>>> A related thing would be canonicalizing unsigned X plus CST to
>>> unsigned X minus CST'
>>> if CST' has a smaller absolute value than CST. I think currently we
>>> simply canonicalize
>>> to 'plus CST' but also only in fold-const.c, not in match.pd (ah we
>>> do, but only in a simplified manner).
>>
>> I can imagine this could simplify the treatment of some cases, yet I'm
>> already a bit lost with the current cases :)
>
> Yes, but I am lost a bit as well. I don't know the correct conditions to test
> off-head -- I know we may not introduce new undefined overflow ops and
> of course we need to not compute wrong numbers either.
>
>>> That said, can we leave that "trick" out of the patch? I think your
>>> more complicated
>>> "overflows" result from extract_range_from_binary_expr_1 doesn't apply to all
>>> ops (like MULT_EXPR where more complicated cases can arise).
>>
>> There is certainly additional work to be done for MULT_EXPR, I
>> disregarded it so far. For this patch, I'd rather conservatively assume
>> overflow.
>
> Ok...
>
> Richard.
>
>> Regards
>> Robin
>>