[X86] X86DAGToDAGISel: handle BZHI selection too, not just BEXTR.
authorRoman Lebedev <lebedev.ri@gmail.com>
Mon, 22 Oct 2018 14:12:44 +0000 (14:12 +0000)
committerRoman Lebedev <lebedev.ri@gmail.com>
Mon, 22 Oct 2018 14:12:44 +0000 (14:12 +0000)
commit898808504dcc2eb64a2962e40bb3096203d12d6b
treea759bc1e652abc7b2d17e57e7b69b73ebbce3a75
parent7efbd8daf4cbb911518a591186cc8fce87ab0c22
[X86] X86DAGToDAGISel: handle BZHI selection too, not just BEXTR.

Summary:
As discussed in D52304 / IRC, we now have pattern matching for
'bit extract' in two places - tablegen and `X86DAGToDAGISel`.
There are 4 patterns.
And we will have a problem with `x &  (-1 >> (32 - y))` pattern.
* If the mask is one-use, then it is always unfolded into `x << (32 - y) >> (32 - y)` first.
  Thus, the existing test coverage is already broken.
* If it is not one-use, then it is not unfolded, and is matched as BZHI.
* If it is not one-use, we will not match it as BEXTR. And if it is one-use, it will have been unfolded already.
So we will either not handle that pattern for BEXTR, or not have test coverage for it.
This is bad.

As discussed with @craig.topper, let's unify this matching, and do everything in `X86DAGToDAGISel`.
Then we will not have code duplication, and will have proper test coverage.

This indeed does not affect any tests, and this is great.
It means that for these two patterns, the `X86DAGToDAGISel` is identical to the tablegen version.

Please review carefully, i'm not fully sure about that intrinsic change, and introduction of the new `X86ISD` opcode.

Reviewers: craig.topper, RKSimon, spatel

Reviewed By: craig.topper

Subscribers: llvm-commits, craig.topper

Differential Revision: https://reviews.llvm.org/D53164

llvm-svn: 344904
llvm/lib/Target/X86/X86ISelDAGToDAG.cpp
llvm/lib/Target/X86/X86ISelLowering.cpp
llvm/lib/Target/X86/X86ISelLowering.h
llvm/lib/Target/X86/X86InstrInfo.td
llvm/lib/Target/X86/X86IntrinsicsInfo.h