On Fri, 5 Aug 2011, Martin Jambor wrote:

> Hi,
> 
> the patch below fixes PR 49923 by checking for misaligned accesses
> before doing IPA-SRA (on strict alignment targets).  I have checked it
> fixes the issue on compile farm sparc64 and I also included this in a
> bootstrap and testsuite run on an x86_64-linux just to double check.
> 
> OK for trunk and the 4.6 branch?

Ok for now.

I think we need to move this to generic middle-end code and also
do something about partly strict-alignment targets such as x86_64.
Iff expansion would treat expr as if it had non-natural alignment
then when building a MEM_REF replacement with non-BLKmode we have
to use a properly aligned variant type for it.

I think we can trick FRE/PRE to run into exactly the same situation.

I'll put it on my TODO.

Richard.

> Thanks,
> 
> Martin
> 
> 
> 2011-08-04  Martin Jambor  <mjam...@suse.cz>
> 
>       PR middle-end/49923
>       * tree-sra.c (access_precludes_ipa_sra_p): Also check access
>       memory alignment.
> 
>       * testsuite/gcc.dg/tree-ssa/pr49923.c: New test.
> 
> 
> Index: src/gcc/tree-sra.c
> ===================================================================
> --- src.orig/gcc/tree-sra.c
> +++ src/gcc/tree-sra.c
> @@ -3688,6 +3688,9 @@ access_precludes_ipa_sra_p (struct acces
>         || gimple_code (access->stmt) == GIMPLE_ASM))
>      return true;
>  
> +  if (tree_non_mode_aligned_mem_p (access->expr))
> +    return true;
> +
>    return false;
>  }
>  
> Index: src/gcc/testsuite/gcc.dg/tree-ssa/pr49923.c
> ===================================================================
> --- /dev/null
> +++ src/gcc/testsuite/gcc.dg/tree-ssa/pr49923.c
> @@ -0,0 +1,55 @@
> +/* { dg-do run } */
> +/* { dg-options "-O3" } */
> +
> +#define PACKED __attribute__(( packed ))
> +
> +struct PACKED aostk_point_u8 {
> +  unsigned char x;
> +  unsigned char y;
> +};
> +
> +struct PACKED aostk_size_u8 {
> +  unsigned char width;
> +  unsigned char height;
> +};
> +
> +struct PACKED aostk_glyph {
> +     unsigned short i;
> +     struct aostk_size_u8 size;
> +     char top;
> +     struct aostk_point_u8 advance;
> +     unsigned char pitch;
> +     unsigned char* data;
> +     char left;
> +};
> +
> +
> +struct PACKED aostk_font {
> +     unsigned short numglyphs;
> +     unsigned char height;
> +     struct aostk_glyph* glyphs;
> +};
> +
> +struct aostk_font glob_font;
> +
> +static struct aostk_glyph* aostk_get_glyph(struct aostk_font* f, unsigned 
> int c) {
> +     return f->glyphs;
> +}
> +
> +int aostk_font_strwidth(struct aostk_font* font, const char* str) {
> +     struct aostk_glyph* g = aostk_get_glyph(font, 0);
> +     return (g != 0);
> +}
> +
> +struct aostk_font*
> +__attribute__ ((noinline, noclone))
> +get_some_font (void)
> +{
> +  return &glob_font;
> +}
> +
> +int main (int argc, char *argv[])
> +{
> +  return (int) aostk_font_strwidth (get_some_font (), "sth");
> +  
> +}
> 
> 

-- 
Richard Guenther <rguent...@suse.de>
Novell / SUSE Labs
SUSE LINUX Products GmbH - Nuernberg - AG Nuernberg - HRB 16746
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer

Reply via email to