This partially implements isBitfieldExtractOpFromAnd from AArch64ISelDAGtoDAG.
It only handles the simplest case. That is,
%mask = G_CONSTANT %constant = G_CONSTANT %lshr = G_LSHR %something, %constant %dst = G_AND %lshr, %mask
becomes
%dst = ubfm %something, immr, imms
To separate the matching from selection, and to avoid adding this to earlySelect, this is done in the post-legalizer combiner. This adds a target-specific G_UBFM instruction which is selected to UBFMWri or UBFMXri depending on the destination size.
The only thing that bothers me about this approach is that in one of the currently-unimplemented cases AArch64ISelDAGtoDAG sometimes inserts a SUBREG_TO_REG. I'm not sure how we would accomplish the same thing in the combiner right now.
I think we should introduce a generic code for these and combine to it. Currently at least 4 backends are reproducing all of the patterns to match it