[InstCombine] fold fake vector extract to shift+trunc
authorSanjay Patel <spatel@rotateright.com>
Wed, 6 Oct 2021 11:42:06 +0000 (07:42 -0400)
committerSanjay Patel <spatel@rotateright.com>
Wed, 6 Oct 2021 12:12:05 +0000 (08:12 -0400)
commitdb231ebdb07f38f8b5d92311a4dc89e63c5a9d05
treeff958f88dd005812787d1b22fcaf84f0ce7d6f36
parent02e690ba0b10c422cbec77105eb40835dab57092
[InstCombine] fold fake vector extract to shift+trunc

We already handle more complicated cases like:
extelt (bitcast (inselt poison, X, 0)) --> trunc (lshr X)

But we missed this simpler pattern:
https://alive2.llvm.org/ce/z/D55h64 / https://alive2.llvm.org/ce/z/GKzzRq

This is part of solving:
https://llvm.org/PR52057

I made the transform depend on legal/desirable int type to avoid creating
a shift of an illegal type (for example i128). I'm not sure if that
restriction is actually necessary, but we can change that as a follow-up
if the backend can deal with integer ops on too-wide illegal types.

The pile of AVX512 test changes are all neutral AFAICT - the x86 backend
seems to know how to turn that into the expected "kmov" instructions.

Differential Revision: https://reviews.llvm.org/D111082
llvm/lib/Transforms/InstCombine/InstCombineInternal.h
llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
llvm/test/Transforms/InstCombine/X86/x86-avx512-inseltpoison.ll
llvm/test/Transforms/InstCombine/X86/x86-avx512.ll
llvm/test/Transforms/InstCombine/extractelement.ll