[X86] `DAGTypeLegalizer::ModifyToType()`: when widening w/ zeros, insert into undef...
authorRoman Lebedev <lebedev.ri@gmail.com>
Mon, 24 Oct 2022 17:11:19 +0000 (20:11 +0300)
committerRoman Lebedev <lebedev.ri@gmail.com>
Mon, 24 Oct 2022 17:27:02 +0000 (20:27 +0300)
commit377f27be87f92e82902be277bb02c401475c9aa1
tree1a108e60ad366ae7aeb103592a0aef6c70e23764
parent52930162870fee52d0d9c07c5d66e5dce32b08e8
[X86] `DAGTypeLegalizer::ModifyToType()`: when widening w/ zeros, insert into undef and `and`-mask the padding away

We can expect that the sequence of inserting-of-extracts-into-undef
will be successfully lowered back into widening of the source vector,
but it seems that at least for X86 mask vectors, we have a really hard time
recovering from inserting-into-zero.

I've looked into alternative fix injection points, and they are much more
involved, by the time of `LowerBUILD_VECTORvXi1()`/`LowerINSERT_VECTOR_ELT()`
the constants might be obscured, so it does not seem like we can easily
deal with this by lowering into bit math later on,
some other pieces are missing.

Instead, it seems like just clearing the padding away via an `AND`-mask
is at least not a worse choice. Why create a problem where there wasn't one.
Though yes, it is possible that there are cases where constants originate
from the source IR, so some other fix may still be needed.

Reviewed By: pengfei

Differential Revision: https://reviews.llvm.org/D136046
llvm/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp
llvm/test/CodeGen/X86/masked_gather_scatter.ll
llvm/test/CodeGen/X86/masked_store.ll
llvm/test/CodeGen/X86/pr45563-2.ll
llvm/test/CodeGen/X86/pr45833.ll