[InstCombine] Fold extractelt with select of constants
authorThomas Symalla <github@thomassymalla.de>
Mon, 14 Nov 2022 08:45:58 +0000 (09:45 +0100)
committerThomas Symalla <thomas.symalla@amd.com>
Tue, 22 Nov 2022 13:07:06 +0000 (14:07 +0100)
commit470aea5ed403d43b68e2ffdbec451d79913eb15d
tree1bf37b9ae55da393bc29b41b88e6511d5b9ab5ab
parent01023bfcd33f922ed8c934ce563e54abe8bfe246
[InstCombine] Fold extractelt with select of constants

An extractelt with a constant index which extracts an element from the
two vector operands of a select can be directly folded into a select.

extractelt (select %x, %vec1, %vec2), %const ->
select %x, %vec1[%const], %vec2[%const]

Note: the implementation currently only works for constant vector operands.

Reviewed By: foad, spatel

Differential Revision: https://reviews.llvm.org/D137934
llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
llvm/test/Transforms/InstCombine/extractelement.ll
llvm/test/Transforms/InstCombine/shufflevector-div-rem-inseltpoison.ll
llvm/test/Transforms/InstCombine/shufflevector-div-rem.ll