This is an archive of the discontinued LLVM Phabricator instance.

[AArch64][GlobalISe] Fold G_AND and G_LSHR into ubfm
Needs ReviewPublic

Authored by paquette on Jul 24 2020, 1:03 PM.

Details

Reviewers
aemerson
Summary

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.

Diff Detail

Event Timeline

paquette created this revision.Jul 24 2020, 1:03 PM

It seems simpler to me to handle this in the selector directly. I’m not sure why a SUBREG_TO_REG is an issue for us in the combiner, but if this could also help O0 it’s better there for now.

If there’s a custom SD node that we want to combine to however that makes more sense to put in the post-legal combiner.

Sure, that sounds fine to me. The code is about the same either way.

paquette updated this revision to Diff 280980.Jul 27 2020, 11:04 AM
  • Do the combine in the selector
  • Regenerate a testcase which had a codegen change, but also was generally wonked up
arsenm added a subscriber: arsenm.Jul 27 2020, 11:10 AM
arsenm added inline comments.
llvm/lib/Target/AArch64/GISel/AArch64InstructionSelector.cpp
1710–1718

Why not use mi_match?

arsenm added inline comments.Jul 27 2020, 11:11 AM
llvm/lib/Target/AArch64/GISel/AArch64InstructionSelector.cpp
1681

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

aemerson added inline comments.Jul 27 2020, 11:48 AM
llvm/lib/Target/AArch64/GISel/AArch64InstructionSelector.cpp
1681

A generic opcode for UBFM? Seems a bit specific to me.

arsenm added inline comments.Jul 27 2020, 11:53 AM
llvm/lib/Target/AArch64/GISel/AArch64InstructionSelector.cpp
1681

It's not very specific, the only target specific detail here is that the fields need to be immediates. BFE and BFM are available on multiple targets, and every target with these shouldn't have to reproduce the same matching logic

aemerson added inline comments.Jul 27 2020, 11:35 PM
llvm/lib/Target/AArch64/GISel/AArch64InstructionSelector.cpp
1681

Fair enough. A G_BITFIELD_EXTRACT operation could be useful enough to justify inclusion then.