This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [patch] for PR 17949


Hello,

> > I don't understand your example (there is no array in it?)
> 
> Still bus errors on Alpha with your patch:
> 
>     typedef struct
>     {
>         int x;
>         short i;
>         int f __attribute__ ((packed));
>     } A;
> 
>     A a[3];
>     int i;
> 
>     main ()
>     {
>         int j;
>         for (j = 0; j < 2; j++)
>                 i += a[j].f;
>     }

OK, here is the new version of the patch that catches also this case.
Bootstapped & regtested on i686 and ia64.

Zdenek

	PR tree-optimization/17949
	* tree-ssa-loop-ivopts.c (may_be_unaligned_p): New function.
	(find_interesting_uses_address): Use it.

Index: tree-ssa-loop-ivopts.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-ssa-loop-ivopts.c,v
retrieving revision 2.39
diff -c -3 -p -r2.39 tree-ssa-loop-ivopts.c
*** tree-ssa-loop-ivopts.c	25 Dec 2004 22:53:54 -0000	2.39
--- tree-ssa-loop-ivopts.c	1 Jan 2005 12:09:32 -0000
*************** idx_record_use (tree base, tree *idx,
*** 1400,1405 ****
--- 1400,1436 ----
    return true;
  }
  
+ /* Returns true if memory reference REF may be unaligned.  */
+ 
+ static bool
+ may_be_unaligned_p (tree ref)
+ {
+   tree base;
+   tree base_type;
+   HOST_WIDE_INT bitsize;
+   HOST_WIDE_INT bitpos;
+   tree toffset;
+   enum machine_mode mode;
+   int unsignedp, volatilep;
+   unsigned base_align;
+ 
+   /* The test below is basically copy of what expr.c:normal_inner_ref
+      does to check whether the object must be loaded by parts when
+      STRICT_ALIGNMENT is true.  */
+   base = get_inner_reference (ref, &bitsize, &bitpos, &toffset, &mode,
+ 			      &unsignedp, &volatilep, true);
+   base_type = TREE_TYPE (base);
+   base_align = TYPE_ALIGN (base_type);
+ 
+   if (mode != BLKmode
+       && (base_align < GET_MODE_ALIGNMENT (mode)
+ 	  || bitpos % GET_MODE_ALIGNMENT (mode) != 0
+ 	  || bitpos % BITS_PER_UNIT != 0))
+     return true;
+ 
+   return false;
+ }
+ 
  /* Finds addresses in *OP_P inside STMT.  */
  
  static void
*************** find_interesting_uses_address (struct iv
*** 1415,1420 ****
--- 1446,1455 ----
        && DECL_NONADDRESSABLE_P (TREE_OPERAND (base, 1)))
      goto fail;
  
+   if (STRICT_ALIGNMENT
+       && may_be_unaligned_p (base))
+     goto fail;
+ 
    ifs_ivopts_data.ivopts_data = data;
    ifs_ivopts_data.stmt = stmt;
    ifs_ivopts_data.step_p = &step;


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]