This is an archive of the discontinued LLVM Phabricator instance.

ARM: Add additional matching for UBFX instructions.
ClosedPublic

Authored by dmgreen on May 26 2016, 12:56 AM.

Details

Summary

This adds an additional matcher to select UBFX(..) from SRL(AND(..)) in ARMISelDAGToDAG to help with code size.

Diff Detail

Repository
rL LLVM

Event Timeline

dmgreen updated this revision to Diff 58577.May 26 2016, 12:56 AM
dmgreen retitled this revision from to ARM: Add additional matching for UBFX instructions..
dmgreen updated this object.
dmgreen set the repository for this revision to rL LLVM.
dmgreen added a subscriber: llvm-commits.

Hi David,

This looks good generally to me. But is there an obvious way to extend this to handle SBFX as well?

James

Hey James, cheers for taking a look at this.

For adding SBFX support; there might some cases to do with sign extending i16/i8's, but are probably quite limited in scope. The top bit of the AND would need to be set. Most such sequences of an AND+ASR are already either optimised to an AND+LSR, so will get caught by this change, or end up as just an ASR as the AND becomes superfluous.

This change was motivated by code like this:

int example(unsigned int x, unsigned int *y) {
    if (x == 1) {
        return (*y & (1 << 5U)) != 0;
    } else if (x == 2) {
        return (*y & (1 << 6U)) != 0;
    }
    return 0;
}

which was coming through as an AND+LSR. I made it a little more general to handle shifted mask AND operands, not just powers of 2, but in this case SBFX isn't as useful.

jmolloy accepted this revision.May 27 2016, 2:08 AM
jmolloy added a reviewer: jmolloy.

Thanks for the clarification David.

This LGTM.

This revision is now accepted and ready to land.May 27 2016, 2:08 AM
This revision was automatically updated to reflect the committed changes.