[DAG] visitINSERT_VECTOR_ELT - attempt to reconstruct BUILD_VECTOR before other fold...
authorSimon Pilgrim <llvm-dev@redking.me.uk>
Mon, 13 Jun 2022 10:47:14 +0000 (11:47 +0100)
committerSimon Pilgrim <llvm-dev@redking.me.uk>
Mon, 13 Jun 2022 10:48:18 +0000 (11:48 +0100)
commit7d8fd4f5db0dd52cf9802889690aab876ad6646b
tree49a66b530b2e3aaa416b9366c4cf074d390684cc
parentf97e15ef455f8235521fd1642f29b08ebfb746ff
[DAG] visitINSERT_VECTOR_ELT - attempt to reconstruct BUILD_VECTOR before other fold interfere

Another issue unearthed by D127115

We take a long time to canonicalize an insert_vector_elt chain before being able to convert it into a build_vector - even if they are already in ascending insertion order, we fold the nodes one at a time into the build_vector 'seed', leaving plenty of time for other folds to alter it (in particular recognising when they come from extract_vector_elt resulting in a shuffle_vector that is much harder to fold with).

D127115 makes this particularly difficult as we're almost guaranteed to have the lost the sequence before all possible insertions have been folded.

This patch proposes to begin at the last insertion and attempt to collect all the (oneuse) insertions right away and create the build_vector before its too late.

Differential Revision: https://reviews.llvm.org/D127595
13 files changed:
llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
llvm/test/CodeGen/AArch64/arm64-neon-copy.ll
llvm/test/CodeGen/AArch64/sve-fixed-length-insert-vector-elt.ll
llvm/test/CodeGen/AArch64/vecreduce-propagate-sd-flags.ll
llvm/test/CodeGen/ARM/neon-copy.ll
llvm/test/CodeGen/RISCV/rvv/fixed-vectors-insert-i1.ll
llvm/test/CodeGen/RISCV/rvv/fixed-vectors-masked-gather.ll
llvm/test/CodeGen/X86/avx512-insert-extract.ll
llvm/test/CodeGen/X86/masked_gather_scatter.ll
llvm/test/CodeGen/X86/shuffle-extract-subvector.ll
llvm/test/CodeGen/X86/sse-insertelt-from-mem.ll
llvm/test/CodeGen/X86/sse-insertelt.ll
llvm/test/CodeGen/X86/vec_insert-7.ll