[InstCombine] canonicalize insertelement order based on index
authorSanjay Patel <spatel@rotateright.com>
Sun, 18 Dec 2022 11:55:37 +0000 (06:55 -0500)
committerSanjay Patel <spatel@rotateright.com>
Sun, 18 Dec 2022 12:08:48 +0000 (07:08 -0500)
commitd5f8878a6e7db01004a3bf61f6b6efbb7d5add25
treeb814e87f8bffec4156dffa35cd4a801d3b27a182
parent9ec5b512b67013f0b78460061a6c984a709f423f
[InstCombine] canonicalize insertelement order based on index

This puts lower insert indexes before higher. This is independent
of endian, so it requires an adjustment to a fold added with
4446f71ce392, but it makes that fold more robust.
That's also where this patch was suggested - D139668.

This matches what we already do in DAGCombiner, but there is one
more constraint because there's an existing canonicalization for
insert-of-scalar-constant. I'm not sure if that is still needed,
so it may be adjusted/removed as a follow-up.
llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
llvm/test/Transforms/InstCombine/broadcast-inseltpoison.ll
llvm/test/Transforms/InstCombine/broadcast.ll
llvm/test/Transforms/InstCombine/insert-extract-shuffle-inseltpoison.ll
llvm/test/Transforms/InstCombine/insert-extract-shuffle.ll
llvm/test/Transforms/InstCombine/insertelt-trunc.ll
llvm/test/Transforms/InstCombine/vec_shuffle-inseltpoison.ll
llvm/test/Transforms/InstCombine/vec_shuffle.ll
llvm/test/Transforms/PhaseOrdering/X86/vector-reductions.ll