------- Comment #14 from law at redhat dot com 2010-02-09 23:04 ------- Subject: Re: vectorizer created unaligned vector insns
On 01/18/10 05:17, irar at il dot ibm dot com wrote: > ------- Comment #13 from irar at il dot ibm dot com 2010-01-18 12:17 ------- > Does something like this make sense? (With this patch we will never use > peeling > for function parameters, unless the builtin returns OK to peel for packed > types). > > Index: tree-vect-data-refs.c > =================================================================== > --- tree-vect-data-refs.c (revision 155880) > +++ tree-vect-data-refs.c (working copy) > @@ -1010,10 +1010,29 @@ vector_alignment_reachable_p (struct dat > tree type = (TREE_TYPE (DR_REF (dr))); > tree ba = DR_BASE_OBJECT (dr); > bool is_packed = false; > + tree tmp = TREE_TYPE (DR_BASE_ADDRESS (dr)); > > if (ba) > is_packed = contains_packed_reference (ba); > > + is_packed = is_packed || contains_packed_reference (DR_BASE_ADDRESS > (dr)); > + > + if (!is_packed) > + { > + while (tmp) > + { > + is_packed = TYPE_PACKED (tmp); > + if (is_packed) > + break; > + > + tmp = TREE_TYPE (tmp); > + } > + } > + > + if (TREE_CODE (DR_BASE_ADDRESS (dr)) == SSA_NAME > +&& TREE_CODE (SSA_NAME_VAR (DR_BASE_ADDRESS (dr))) == PARM_DECL) > + is_packed = true; > + > if (vect_print_dump_info (REPORT_DETAILS)) > fprintf (vect_dump, "Unknown misalignment, is_packed = > %d",is_packed); > if (targetm.vectorize.vector_alignment_reachable (type, is_packed)) > > I still don't see how this can be conservatively correct. The fundamental problem is the code assumes that if it doesn't find a packed attribute or the DR_BASE_ADDRESS isn't directly derived from a PARM_DECL then it's safe to vectorize. Instead the code really needs to operate by proving suitable alignment and if suitable alignment can't be proven, then vectorization is not possible without runtime alignment guards. As an example, consider the case where an unaligned packed address is passed as a parameter, but the target function does somethign like fubar (int *p, bool condition ) // where P is potentially unaligned { int *addr; if (condition) temp = malloc (whatever) addr = (condition ? temp : p); // addr used as base address in vectorizable loop here } Jeff -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42652