This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[patch] for PR 17949
- From: Zdenek Dvorak <rakdver at atrey dot karlin dot mff dot cuni dot cz>
- To: gcc-patches at gcc dot gnu dot org
- Date: Fri, 31 Dec 2004 20:05:36 +0100
- Subject: [patch] for PR 17949
Hello,
ivopts may produce unaligned memory accesses during strength reduction
(when packed attribute is present), which is a problem when
STRICT_ALIGNMENT is true. This patch makes ivopts ignore such
accesses.
I am not quite sure whether may_be_unaligned_p is correct. I think this
is the way it is checked in expand_expr, but the code is not too clear
and I am not very familiar with it.
Bootstrapped and regtested on i686 and ia64 (the later has
STRICT_ALIGNMENT).
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 31 Dec 2004 10:53:13 -0000
*************** idx_record_use (tree base, tree *idx,
*** 1400,1405 ****
--- 1400,1425 ----
return true;
}
+ /* Returns true if memory reference REF may be unaligned. */
+
+ static bool
+ may_be_unaligned_p (tree ref)
+ {
+ tree type = TREE_TYPE (ref);
+ unsigned req_align = TYPE_ALIGN (type);
+ tree base = get_base_address (ref);
+ tree base_type;
+ unsigned actual_align;
+
+ if (!base)
+ return false;
+
+ base_type = TREE_TYPE (base);
+ actual_align = TYPE_ALIGN (base_type);
+
+ return req_align > actual_align;
+ }
+
/* Finds addresses in *OP_P inside STMT. */
static void
*************** find_interesting_uses_address (struct iv
*** 1415,1420 ****
--- 1435,1444 ----
&& 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;