<div dir="ltr">Just confirmed this (conservatively correct) patch fixed the issue for me, thanks!</div><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, Nov 15, 2013 at 5:12 PM, Hal Finkel <span dir="ltr"><<a href="mailto:hfinkel@anl.gov" target="_blank">hfinkel@anl.gov</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">----- Original Message -----<br>
> From: "Arnold Schwaighofer" <<a href="mailto:aschwaighofer@apple.com">aschwaighofer@apple.com</a>><br>
> To: "Joshua Klontz" <<a href="mailto:josh.klontz@gmail.com">josh.klontz@gmail.com</a>><br>
> Cc: "LLVM Dev" <<a href="mailto:llvmdev@cs.uiuc.edu">llvmdev@cs.uiuc.edu</a>><br>
> Sent: Friday, November 15, 2013 4:05:53 PM<br>
> Subject: Re: [LLVMdev] Limit loop vectorizer to SSE<br>
><br>
><br>
> Something like:<br>
><br>
> index 6db7f68..68564cb 100644<br>
> --- a/lib/Transforms/Vectorize/LoopVectorize.cpp<br>
> +++ b/lib/Transforms/Vectorize/LoopVectorize.cpp<br>
> @@ -1208,6 +1208,8 @@ void<br>
> InnerLoopVectorizer::vectorizeMemoryInstruction(Instr<br>
>    Type *DataTy = VectorType::get(ScalarDataTy, VF);<br>
>    Value *Ptr = LI ? LI->getPointerOperand() :<br>
>    SI->getPointerOperand();<br>
>    unsigned Alignment = LI ? LI->getAlignment() : SI->getAlignment();<br>
> +  if (Alignment == 0)<br>
> +    Alignment = 1;<br>
<br>
</div>That may be conservatively correct, but I don't think it is really right. An alignment of 0 is supposed to mean the platform default alignment (IIRC, DataLayout::getPrefTypeAlignment tells you what it is).<br>
<span class="HOEnZb"><font color="#888888"><br>
 -Hal<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
>    unsigned AddressSpace = Ptr->getType()->getPointerAddressSpace();<br>
>    unsigned ScalarAllocatedSize = DL->getTypeAllocSize(ScalarDataTy);<br>
>    unsigned VectorElementSize = DL->getTypeStoreSize(DataTy)/VF;<br>
><br>
> Should fix this.<br>
><br>
> On Nov 15, 2013, at 3:49 PM, Joshua Klontz <<a href="mailto:josh.klontz@gmail.com">josh.klontz@gmail.com</a>><br>
> wrote:<br>
><br>
> > Nadav,<br>
> ><br>
> > I believe aligned accesses to unaligned pointers is precisely the<br>
> > issue. Consider the function `add_u8S` before[1] and after[2] the<br>
> > loop vectorizer pass. There is no alignment assumption associated<br>
> > with %kernel_data prior to vectorization. I can't tell if it's the<br>
> > loop vectorizer or the codegen at fault, but the alignment<br>
> > assumption seems to sneak in somewhere.<br>
> ><br>
> > v/r,<br>
> > Josh<br>
> ><br>
> > [1] <a href="http://pastebin.com/kc95WtGG" target="_blank">http://pastebin.com/kc95WtGG</a><br>
> > [2] <a href="http://pastebin.com/VY3ZLVJK" target="_blank">http://pastebin.com/VY3ZLVJK</a><br>
> ><br>
> ><br>
> > On Fri, Nov 15, 2013 at 3:58 PM, Nadav Rotem <<a href="mailto:nrotem@apple.com">nrotem@apple.com</a>><br>
> > wrote:<br>
> ><br>
> > On Nov 15, 2013, at 12:36 PM, Renato Golin<br>
> > <<a href="mailto:renato.golin@linaro.org">renato.golin@linaro.org</a>> wrote:<br>
> ><br>
> >> On 15 November 2013 20:24, Joshua Klontz <<a href="mailto:josh.klontz@gmail.com">josh.klontz@gmail.com</a>><br>
> >> wrote:<br>
> >> Agreed, is there a pass that will insert a runtime alignment<br>
> >> check? Also, what's the easiest way to get at<br>
> >> TargetTransformInfo::getRegisterBitWidth() so I don't have to<br>
> >> hard code 32? Thanks!<br>
> >><br>
> >> I think that's a fair question, and it's about safety. If you're<br>
> >> getting this on the JIT, means we may be generating unsafe<br>
> >> transformations on the vectorizer.<br>
> >><br>
> >> Arnold, Nadav, I don't remember seeing code to generate any<br>
> >> run-time alignment checks on the incoming pointer, is there such<br>
> >> a thing? If not, shouldn't we add one?<br>
> ><br>
> ><br>
> > If the the vectorizer generates aligned memory accesses to<br>
> > unaligned addresses then this is a serious bug.  But I don’t think<br>
> > that Josh said that the vectorizer generated aligned accesses to<br>
> > unaligned pointers.<br>
> ><br>
> > There is no point in LLVM checking for alignment because if the<br>
> > memory is unaligned then the program will crash.  Users who want<br>
> > to crash with a readable error message can simply write code that<br>
> > checks the pointer (by masking the high bits and comparing to<br>
> > zero).<br>
> ><br>
> ><br>
><br>
><br>
</div></div><div class="HOEnZb"><div class="h5">> _______________________________________________<br>
> LLVM Developers mailing list<br>
> <a href="mailto:LLVMdev@cs.uiuc.edu">LLVMdev@cs.uiuc.edu</a>         <a href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a><br>
> <a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br>
><br>
</div></div></blockquote></div><br></div>