This is an archive of the discontinued LLVM Phabricator instance.

[ARM] Check for unaligned access via bitcasts
AbandonedPublic

Authored by samparker on Jun 18 2018, 1:49 AM.

Details

Summary

The load/store optimiser will convert sequential ldr/str instructions into ldrd/strd and these instructions cannot access unaligned memory.

When generating DSP instructions, we can use ldr/str instructions to load and store packed data but this means that it can be possible for those instructions to be accessing unaligned memory. This is fine for processors which support unaligned accesses, but it is not fine if these instructions are then optimised into ldrd/strd.

This patch modified ARMLoadStoreOpt pass to look through the pointer information to determine if the access size of the memory operation is safe for the optimisation. We now don't perform the transform if the access type is wider than the memory type.

This patch is to support the transformation being performed in D48128.

Diff Detail

Event Timeline

samparker created this revision.Jun 18 2018, 1:49 AM
efriedma requested changes to this revision.Jun 18 2018, 1:00 PM

In IR, if a pointer operand doesn't have the alignment given by the "align" annotation, the behavior is undefined. (If you don't explicitly specify the alignment, it defaults to the alignment specified in the DataLayout.) Similarly, in a MachineFunction, if a memory operation accesses an address which doesn't have the alignment given in the MMO, the behavior is undefined.

Looking at ARMParallelDSP::CreateSMLADCall in D48128, it looks like you forgot to set the alignment on the loads you're creating.

This revision now requires changes to proceed.Jun 18 2018, 1:00 PM
samparker abandoned this revision.Jun 19 2018, 12:59 AM

Many thanks Eli!