[X86][InstCombine] Add constant folding and simplification support for pdep and pext
authorCraig Topper <craig.topper@intel.com>
Tue, 31 Dec 2019 23:06:47 +0000 (15:06 -0800)
committerCraig Topper <craig.topper@intel.com>
Tue, 31 Dec 2019 23:06:47 +0000 (15:06 -0800)
commit374e0299cf08dc1ff2c68e7f6c159b98ab55dfb8
tree09a3f096082cee0c493c77478a7318a1a014f619
parent1cc8a74de345b66fd340ddc71580ad412e8e2abf
[X86][InstCombine] Add constant folding and simplification support for pdep and pext

The instructions use a mask to either pack disjoint bits together(pext) or spread bits to disjoint locations(pdep). If the mask is all 0s then no bits are extracted or deposited. If the mask is all ones, then the source value is written to the result since no compression or expansion happens. Otherwise if both the source and mask are constant we can walk the bits in the source/mask and calculate the result.

There other crazier things we could do like computeKnownBits or turning pext into shift/and if only a single contiguous range of bits is extracted.

Fixes PR44389

Differential Revision: https://reviews.llvm.org/D71952
llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
llvm/test/Transforms/InstCombine/X86/x86-bmi-tbm.ll