[PATCH] D27861: [DAGCombiner] Match load by bytes idiom and fold it into a single load. Attempt #2.

Artur Pilipenko via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 16 13:48:51 PST 2016

apilipenko created this revision.
apilipenko added reviewers: hfinkel, RKSimon, filcab, chandlerc.
apilipenko added a subscriber: llvm-commits.

The previous patch (https://reviews.llvm.org/rL289538) got reverted because of a bug. Chandler also requested some changes to the algorithm.

This is an updated patch. The key difference is that collectBitProviders now collects the origin of one byte, not the whole value. It simplifies the implementation and allows to stop the traversal earlier if we know that the result won't be used.

From the original review:

Match a pattern where a wide type scalar value is loaded by several narrow loads and combined by shifts and ors. Fold it into a single load or a load and a bswap if the targets supports it.

Assuming little endian target:

  i8 *a = ...
  i32 val = a[0] | (a[1] << 8) | (a[2] << 16) | (a[3] << 24)


  i32 val = *((i32)a)

  i8 *a = ...
  i32 val = (a[0] << 24) | (a[1] << 16) | (a[2] << 8) | a[3]


  i32 val = BSWAP(*((i32)a))



-------------- next part --------------
A non-text attachment was scrubbed...
Name: D27861.81793.patch
Type: text/x-patch
Size: 64931 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161216/76ffc995/attachment-0001.bin>

More information about the llvm-commits mailing list