This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH, PR43814] Assume function arguments of pointer type are aligned.
- From: Tom de Vries <Tom_deVries at mentor dot com>
- To: Carrot Wei <carrot at google dot com>
- Cc: Tom de Vries <vries at codesourcery dot com>, Richard Guenther <richard dot guenther at gmail dot com>, "gcc-patches at gcc dot gnu dot org" <gcc-patches at gcc dot gnu dot org>, Maxim Kuvyrkov <maxim at codesourcery dot com>
- Date: Wed, 28 Sep 2011 18:22:53 +0200
- Subject: Re: [PATCH, PR43814] Assume function arguments of pointer type are aligned.
- References: <4E787543.1090009@codesourcery.com> <CAEe8uECBmjaXEGAfSscHZGxbLKA5Qi_LibhhFbZ_MEFMQvHGWw@mail.gmail.com>
On 09/28/2011 03:57 PM, Carrot Wei wrote:
> Hi Tom
>
> What's the behavior of your patch to the following case
>
> typedef int int_unaligned __attribute__((aligned(1)));
> int foo (int_unaligned *p)
> {
> return *p;
> }
>
I modified the example slightly:
test.c:
...
typedef int __attribute__((aligned(2))) int_unaligned;
int foo (int_unaligned *p)
{
return *(p+1);
}
...
test.c.023t.ccp1:
...
# PT = anything
# ALIGN = 2, MISALIGN = 0
D.2723_2 = pD.1604_1(D) + 4;
...
Thanks,
- Tom
> thanks
> Carrot
>
> On Tue, Sep 20, 2011 at 7:13 PM, Tom de Vries <vries@codesourcery.com> wrote:
>> Hi Richard,
>>
>> I have a patch for PR43814. It introduces an option that assumes that function
>> arguments of pointer type are aligned, and uses that information in
>> tree-ssa-ccp. This enables the memcpy in pr43814-2.c to be inlined.
>>
>> I tested the patch successfully on-by-default on x86_64 and i686 (both gcc only
>> builds).
>>
>> I also tested the patch on-by-default for ARM (gcc/glibc build). The patch
>> generated wrong code for uselocale.c:
>> ...
>> glibc/locale/locale.h:
>> ...
>> /* This value can be passed to `uselocale' and may be returned by
>> it. Passing this value to any other function has undefined behavior. */
>> # define LC_GLOBAL_LOCALE ((__locale_t) -1L)
>> ...
>> glibc/locale/uselocale.c:
>> ...
>> locale_t
>> __uselocale (locale_t newloc)
>> {
>> locale_t oldloc = _NL_CURRENT_LOCALE;
>>
>> if (newloc != NULL)
>> {
>> const locale_t locobj
>> = newloc == LC_GLOBAL_LOCALE ? &_nl_global_locale : newloc;
>>
>> ...
>> The assumption that function arguments of pointer type are aligned, allowed the
>> test 'newloc == LC_GLOBAL_LOCALE' to evaluate to false.
>> But the usage of ((__locale_t) -1L) as function argument in uselocale violates
>> that assumption.
>>
>> Fixing the definition of LC_GLOBAL_LOCALE allowed the gcc tests to run without
>> regressions for ARM.
>>
>> Furthermore, the patch fixes ipa-sra-2.c and ipa-sra-6.c regressions on ARM,
>> discussed here:
>> - http://gcc.gnu.org/ml/gcc-patches/2011-08/msg00930.html
>> - http://gcc.gnu.org/ml/gcc-patches/2011-09/msg00459.html
>>
>> But, since glibc uses this construct currently, the option is off-by-default for
>> now.
>>
>> OK for trunk?
>>
>> Thanks,
>> - Tom
>>
>> 2011-09-20 Tom de Vries <tom@codesourcery.com>
>>
>> PR target/43814
>> * tree-ssa-ccp.c (get_align_value): New function, factored out of
>> get_value_from_alignment.
>> (get_value_from_alignment): Use get_align_value.
>> (get_value_for_expr): Use get_align_value to handle alignment of
>> function argument pointers.
>> * common.opt (faligned-pointer-argument): New option.
>> * doc/invoke.texi (Optimization Options): Add
>> -faligned-pointer-argument.
>> (-faligned-pointer-argument): New item.
>>
>> * gcc/testsuite/gcc.dg/pr43814.c: New test.
>> * gcc/testsuite/gcc.target/arm/pr43814-2.c: New test.
>>