<div dir="ltr"><div><br></div>What is the proper solution to disable auto-vectorization for unaligned data?<div><br></div><div>I have an out of tree target and I added this:</div><div><br></div><div><div>bool OpusTargetLowering::allowsUnalignedMemoryAccesses(EVT VT, bool *Fast) const {</div>
<div> if (VT.isVector())</div><div> return false;</div></div><div>....</div><div>}</div><div><br></div><div>After that, I could see that vectorization is still done on unaligned data except that llvm will copy the data back and forth from the source to the top of the stack and work from there. This is very costly, I rather get scalar operations.</div>
<div><br></div><div>Then I tried to add:</div><div><div> unsigned getMemoryOpCost(unsigned Opcode, Type *Src,</div><div> unsigned Alignment,</div><div> unsigned AddressSpace) const {</div>
<div> if (Src->isVectorTy() && Alignment != 16)</div><div> return 10000; // <== high number to try to avoid unaligned load/store.</div></div><div><div> return TargetTransformInfo::getMemoryOpCost(Opcode, Src, Alignment, AddressSpace);</div>
<div> }</div></div><div><br></div><div>Except that this doesn't work because Alignment will always be 4 even for data like:</div><div><div> int data[16][16] __attribute__ ((aligned (16))),</div></div><div><br>
</div><div>Because individual element are still 4-byte aligned.</div><div><br></div><div>I am not sure what is the right way to do it?</div><div>Thanks.</div><div><br></div></div>