[PATCH] D138874: [InstCombine] canonicalize trunc + insert as bitcast + shuffle, part 3

Sanjay Patel via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 28 15:34:51 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 a project: LLVM.
Herald added a subscriber: llvm-commits.

This enhances the folds from part 1 and part 2 to allow insertion into an arbitrary vector. This means we form a select-shuffle (no cross-lane movement is allowed).

Example proofs with endian diffs:
https://alive2.llvm.org/ce/z/Mqfgt8

We can create a select-shuffle for all targets because targets are expected to be able to lower select-shuffles reasonably. This transform could be generalized further if it was implemented in a target-specific pass (with a cost/legality model).

The transform can result in more instructions than we started with (in the case where the vector size is longer/shorter than the scalar), but I think that's a reasonable trade-off to make the canonicalization more consistent.

This allows removing a pair of instructions from the motivating example from issue #17113 <https://github.com/llvm/llvm-project/issues/17113>, but it is still not the ideal IR/codegen.


https://reviews.llvm.org/D138874

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

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D138874.478385.patch
Type: text/x-patch
Size: 16967 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221128/ffe9c28a/attachment.bin>


More information about the llvm-commits mailing list