ivopts improvement
Tom de Vries
vries@codesourcery.com
Wed Mar 2 22:01:00 GMT 2011
Hi Zdenek,
On 02/28/2011 07:12 PM, Zdenek Dvorak wrote:
> Hi,
>
>>>>>> I think this should be done unconditionally under
>>>>>> -funsafe-loop-optimizations.
>>>>
>>>> void
>>>> f (char *base, unsigned long int i, unsigned long int n)
>>>> {
>>>> char *p = base + i;
>>>> do
>>>> {
>>>> *p = '\0';
>>>> p++;
>>>> i++;
>>>> }
>>>> while (i< n);
>>>> }
>>>>
>>>> AFAIU, -funsafe-loop-optimizations allows me to assume that i does not
>>>> overflow. Are you saying that -funsafe-loop-optimizations also implies
>>>> that p does not overflow?
>>>
>>> I'm wondering if the C standard doesn't allow you to accept this always, at
>>> least if the increment to i (and p) is positive.
>>>
>>> I'm thinking that "undefined behavior for NULL pointer access" implies that
>>> an object cannot be allocated across a NULL pointer. And since pointer
>>> arithmetic beyond object boundaries is undefined, an overflow of p (which
>>> would cross a NULL pointer) is also undefined.
>>
>> The important thing is that IVOPTs is not allowed to introduce IVs that
>> overflow either. And it is known to create weird IVs starting from
>> -4 ...
>
> as long as we do the arithmetics in unsigned integer type and only cast to the
> pointer type the final result, C standard (plus the gcc-specific interpretation
> of casts) allows us to do that.
>
> Nevertheless, pointer arithmetics has defined behavior only within
> a single memory object or at most one array element after it; which more
> or less forbids overflows, when the arithmetics is performed in pointer
> type,
>
> Zdenek
Another try with updated patches.
Changes compared to last submission:
iterator.6.1-ml.patch:
* removed the stmt_after_increment related code
in may_eliminate_iv (after review comment).
iterator.6.4-ml.patch:
* added test for loop_only_exit_p before calling
iv_elimination_compare_lt. make sure the last loop iteration is
reached, which makes p + n a valid pointer.
* removed cand_valid_pointer_at_use_p and replaced call
with test for (cand->pos == IP_ORIGINAL
&& POINTER_TYPE_P (TREE_TYPE (cand->var_before))
&& POINTER_TYPE_OVERFLOW_UNDEFINED).
In other words, the iterator is a source level pointer iterator, which
is guaranteed not to overflow provided
POINTER_TYPE_OVERFLOW_UNDEFINED.
* return bound in pointer type rather than unsigned int type. Make sure
the bound matches the pointer iterator.
reg-tested on x86-64.
Ok now?
Thanks,
- Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: iterator.6.1-ml.patch
Type: text/x-patch
Size: 1551 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20110302/2e3d7e65/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: iterator.6.4-ml.patch
Type: text/x-patch
Size: 5900 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20110302/2e3d7e65/attachment-0001.bin>
More information about the Gcc-patches
mailing list