[PATCH] D138872: [InstCombine] canonicalize trunc + insert as bitcast + shuffle, part 1

Sanjay Patel via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 28 15:33:30 PST 2022


spatel created this revision.
spatel added reviewers: RKSimon, nikic, dmgreen, lebedev.ri.
Herald added subscribers: hiraditya, mcrosier.
Herald added a project: All.
spatel requested review of this revision.
Herald added subscribers: llvm-commits, pcwang-thead.
Herald added a project: LLVM.

This is the main patch for converting a truncated scalar that is inserted into a vector to bitcast+shuffle. We could go either way on patterns like this, but this direction will allow collapsing a pair of these sequences on the motivating example from issue #17113 <https://github.com/llvm/llvm-project/issues/17113>.

The patch is split into 3 parts to make it easier to see the progression of tests diffs. We allow inserting/shuffling into a different size vector for flexibility, so there are several test variations. The length-changing is handled by shortening/padding the shuffle mask with undef elements.

In part 1, handle the basic pattern:

  inselt undef, (trunc T), IndexC --> shuffle (bitcast T), IdentityMask

Proof for the endian-dependency behaving as expected:
https://alive2.llvm.org/ce/z/BsA7yC

The TODO items for handling shifts and insert into an arbitrary base vector value are implemented as follow-ups.


https://reviews.llvm.org/D138872

Files:
  llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
  llvm/test/Transforms/InstCombine/insert-trunc.ll
  llvm/test/Transforms/InstCombine/vec_phi_extract-inseltpoison.ll
  llvm/test/Transforms/InstCombine/vec_phi_extract.ll
  llvm/test/Transforms/LoopVectorize/ARM/pointer_iv.ll
  llvm/test/Transforms/PhaseOrdering/X86/vec-load-combine.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D138872.478368.patch
Type: text/x-patch
Size: 23537 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221128/4bdd9074/attachment.bin>


More information about the llvm-commits mailing list