[llvm-commits] Invalid instcombine transformation

Anton Korobeynikov anton at korobeynikov.info
Thu Nov 26 12:25:43 PST 2009


Hello, Everyone

Currently instcombine turns small memcpy's (say, of 1/2/4/8 bytes)
into loads / stores. This seems to be invalid if target does not allow
unaligned access (and even if it allows, it's slower in general).
Consider ARM, there we have:
 
1. Byte loads / stores => no alignment requirement
2. 2-byte loads / stores => 16 bit alignment requirement
3. 4-byte loads / stores => 32 bit alignment requirement
 
In case of misaligned access in cases 2 and 3 it can be either "fixed"
(if the processor is configured so), or trap (it it doesn't configured
so).

memcpy allows arbitrary alignment. In such situation, turn of e.g.
memcpy(i8*, i8*, 2, 1) and memcpy(i8*, i8*, 4, 1) into loads / stores
is invalid and thus the transform should be disabled. Same applies to
memset.

Attached patch allows memcpy => load/store transformation only if memcpy
alignment is not lower than ABI alignment of the load/store type (when
TargetData is available).

This fixed several bugs in real code running on ARM.

Ok to commit?

-- 
With best regards, Anton Korobeynikov.

Faculty of Mathematics & Mechanics, Saint Petersburg State University.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: instcombine-unaligned.diff
Type: text/x-patch
Size: 4257 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20091126/5d02154c/attachment.bin>


More information about the llvm-commits mailing list