[PATCH] [InstCombine] Fold endian-independent load sequence into a single load.

Ahmed Bougacha ahmed.bougacha at gmail.com
Tue Oct 21 17:21:36 PDT 2014


Hi majnemer,

This patch combines endian-independent load sequences, that look like this:

(x[3]<<24 | x[2]<<16 | x[1]<<8 | x[0])

into a single load (bswapped if the data endianness is different from the target endianness):

*((int*)x)

One notable issue is alignment: this patch produces 1-aligned loads, no matter the size. In practice, this means that on some targets (ARM comes to mind), the load will codegen into the same original shift/or sequence. I'm not sure if there's a way to discover alignment for this sort of situation. But no matter what, this should always be profitable.

It doesn't happen very often in practice (LNT is still running), so I tried to avoid being too expensive (this is pretty different from the other OR combines).

Also, the combining is aborted if there are *any* stores between the first and last load in the sequence. This needs a loop scanning up from the last instruction. As a safeguard, I put a max number of instructions on that loop, but by then, we already know the combine is valid, so I'm not sure if it's a good idea to abort that late.

Thanks!
- Ahmed

http://reviews.llvm.org/D5898

Files:
  lib/Transforms/InstCombine/InstCombine.h
  lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
  test/Transforms/InstCombine/endian-independent-load-BE.ll
  test/Transforms/InstCombine/endian-independent-load-LE.ll
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D5898.15220.patch
Type: text/x-patch
Size: 23536 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20141022/266b9813/attachment.bin>


More information about the llvm-commits mailing list