This is an archive of the discontinued LLVM Phabricator instance.

[Thumb] Select a BIC instead of AND if the immediate can be encoded more optimally negated
ClosedPublic

Authored by jmolloy on Jun 7 2016, 8:47 AM.

Details

Summary

If an immediate is only used in an AND node, it is possible that the immediate can be more optimally materialized when negated. If this is the case, we can negate the immediate and use a BIC instead;

  int i(int a) {
    return a & 0xfffffeec;
  }

Used to produce:
    ldr r1, [CONSTPOOL]
    ands r0, r1
  CONSTPOOL: 0xfffffeec

And now produces:
    movs    r1, #255
    adds    r1, #20  ; Less costly immediate generation
    bics    r0, r1

Diff Detail

Repository
rL LLVM

Event Timeline

jmolloy updated this revision to Diff 59895.Jun 7 2016, 8:47 AM
jmolloy retitled this revision from to [Thumb] Select a BIC instead of AND if the immediate can be encoded more optimally negated.
jmolloy updated this object.
jmolloy set the repository for this revision to rL LLVM.
jmolloy added a subscriber: llvm-commits.
mcrosier added inline comments.Jun 7 2016, 10:37 AM
lib/Target/ARM/ARMISelDAGToDAG.cpp
2799–2838

Please add a very brief description here similar to what is in your summary.

2808

How about 'TransformImm', 'UseBIC' or 'PreferBIC'?

sbaranga added inline comments.Jun 8 2016, 6:33 AM
lib/Target/ARM/ARMISelDAGToDAG.cpp
2801

If the constant ends up as an immediate, why limit it to only having one use?

jmolloy added inline comments.Jun 8 2016, 6:56 AM
lib/Target/ARM/ARMISelDAGToDAG.cpp
2801

The constant doesn't end up as an immediate. That's what the "ImmTransform" check below is doing - if it would just be promoted to an immediate, don't bother and bail out.

But if it can't be an immediate, then do the transform. And in that case we don't want to create more constants.

jmolloy updated this revision to Diff 60028.Jun 8 2016, 6:57 AM

Thanks Chad and Silviu for the review.

Updated according to Chad's comments, and hopefully the new name "PreferImmediateEncoding" should address Silviu's comment too.

mcrosier accepted this revision.Jun 8 2016, 7:33 AM
mcrosier edited edge metadata.

LGTM. Feel free to allow Silviu to comment before committing.

This revision is now accepted and ready to land.Jun 8 2016, 7:33 AM

Thanks! committed in r272251.

jmolloy closed this revision.Jun 9 2016, 12:45 AM