This is an archive of the discontinued LLVM Phabricator instance.

[ARM] Combine CMOV into BFI where possible
ClosedPublic

Authored by jmolloy on Nov 4 2015, 7:32 AM.

Details

Summary

If we have a CMOV, OR and AND combination such as:

if (x & CN)
  y |= CM;

And:

  • CN is a single bit;
  • All bits covered by CM are known zero in y;

Then we can convert this to a sequence of BFI instructions. This will always be a win if CM is a single bit, will always be no worse than the TST & OR sequence if CM is two bits, and for thumb will be no worse if CM is three bits (due to the extra IT instruction).

Diff Detail

Event Timeline

jmolloy updated this revision to Diff 39204.Nov 4 2015, 7:32 AM
jmolloy retitled this revision from to [ARM] Combine CMOV into BFI where possible.
jmolloy updated this object.
jmolloy added reviewers: t.p.northover, mcrosier.
jmolloy set the repository for this revision to rL LLVM.
jmolloy added a subscriber: llvm-commits.
mcrosier added inline comments.Nov 4 2015, 8:01 AM
lib/Target/ARM/ARMISelLowering.cpp
10436

I believe the logic in PerformCMOVCombine guarantees this will never be true. Perhaps we could change this to an assert?

10447

Is the Op0->getOpcode() != ISD::OR alone not sufficient?

10471

This should be guarded by a DEBUG macro.

10487

Assuming the call to OrCI.getActiveBits() doesn't change during the lifetime of the loop, this should only be called once to init an end value..

for (unsigned BitInY = 0, E = OrCI.getActiveBits(); BitInY < E; ++BitInY) {

test/CodeGen/ARM/bfi.ll
88

Please add a newline.

jmolloy updated this revision to Diff 39208.Nov 4 2015, 8:13 AM
jmolloy removed rL LLVM as the repository for this revision.

Hi Chad,

Thanks for the quick review! See my updated patch.

Cheers,

James

mcrosier accepted this revision.Nov 4 2015, 8:49 AM
mcrosier edited edge metadata.

LGTM with one request.: Mind adding a test case where CM has 2 set bits? With that in place feel free to commit.

lib/Target/ARM/ARMISelLowering.cpp
10491

How about just a single period?

10516

Please add a period.

This revision is now accepted and ready to land.Nov 4 2015, 8:49 AM
jmolloy closed this revision.Nov 4 2015, 8:57 AM
jmolloy marked 2 inline comments as done.

Thanks Chad! committed with your changes in r252057.