Page MenuHomePhabricator

[ARM] Transform compare of masked value to shift on Thumb1.
ClosedPublic

Authored by efriedma on Jul 23 2019, 5:06 PM.

Details

Summary

Thumb1 has very limited immediate modes, so turning an "and" into a shift can save multiple instructions.

It's possible to simplify the generated code for test2 and test3 in cmp-and-fold.ll a little more, but I'll implement that as a followup.

Diff Detail

Repository
rL LLVM

Event Timeline

efriedma created this revision.Jul 23 2019, 5:06 PM
efriedma edited the summary of this revision. (Show Details)Jul 23 2019, 5:09 PM
ostannard added inline comments.Jul 24 2019, 1:55 AM
lib/Target/ARM/ARMISelLowering.cpp
4065 ↗(On Diff #211387)

I don't see any code implementing this case. Instead, there is a check that Mask > 65535, but this looks like it should still be profitable for masks between 255 and 65535.

Any reason why not to use this for thumb2 as well? It looks like it would be useful for T2 codesize.

efriedma marked an inline comment as done.Jul 24 2019, 3:47 PM

Any reason why not to use this for thumb2 as well?

You can't save any instructions this way on Thumb2; every AND which can be transformed is a legal and/bic/bfc. I guess a narrow lsls+cmp is still two bytes shorter than bic+cmp.

lib/Target/ARM/ARMISelLowering.cpp
4065 ↗(On Diff #211387)

I'll add some tests more tests to cover this, and tweak the heuristic if it seems profitable.

efriedma updated this revision to Diff 212466.Jul 30 2019, 4:22 PM

Updated heuristic to match the underlying encodings a bit more closely.

ostannard accepted this revision.Jul 31 2019, 2:59 AM

LGTM, thanks

This revision is now accepted and ready to land.Jul 31 2019, 2:59 AM
This revision was automatically updated to reflect the committed changes.