[InstCombine] try to fold a pair of insertelements into one insertelement
authorSanjay Patel <spatel@rotateright.com>
Mon, 12 Dec 2022 15:02:56 +0000 (10:02 -0500)
committerSanjay Patel <spatel@rotateright.com>
Mon, 12 Dec 2022 15:39:58 +0000 (10:39 -0500)
commit4446f71ce392a13e64299d4efe9d7c2a2b768c6c
treedc968a05586a1ad80d664a2ab2acc0a0125bc316
parent620d2bfdadeb7f4936775422a0e965e7fcdcd204
[InstCombine] try to fold a pair of insertelements into one insertelement

This replaces patches that tried to convert related patterns to shuffles
(D138872, D138873, D138874 - reverted/abandoned) but caused codegen
problems and were questionable as a canonicalization because an
insertelement is a simpler op than a shuffle.

This detects a larger pattern -- insert-of-insert -- and replaces with
another insert, so this hopefully does not cause any problems.

As noted by TODO items in the code and tests, this could go a lot further.
But this is enough to reduce the motivating test from issue #17113.

Example proofs:
https://alive2.llvm.org/ce/z/NnUv3a

I drafted a version of this for AggressiveInstCombine, but it seems that
would uncover yet another phase ordering gap. If we do generalize this to
handle the full range of potential patterns, that may be worth looking at
again.

Differential Revision: https://reviews.llvm.org/D139668
llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
llvm/test/Transforms/InstCombine/insertelt-trunc.ll
llvm/test/Transforms/PhaseOrdering/X86/vec-load-combine.ll