This is an archive of the discontinued LLVM Phabricator instance.

[ARM] Mark <= -1 immediate constant as cheap
ClosedPublic

Authored by dmgreen on Sep 7 2021, 6:11 AM.

Details

Summary

A <= -1 constant on a compare can be converted to a < 0 operation, which is usually cheap. If we mark the constant as cheap, preventing hoisting, we allow that fold to happen even across different blocks.

Diff Detail

Event Timeline

dmgreen created this revision.Sep 7 2021, 6:11 AM
dmgreen requested review of this revision.Sep 7 2021, 6:11 AM
Herald added a project: Restricted Project. · View Herald TranscriptSep 7 2021, 6:11 AM
samtebbs added inline comments.Sep 21 2021, 9:22 AM
llvm/lib/Target/ARM/ARMTargetTransformInfo.cpp
385

Can this be applied to any integer less than the maximum for the type (e.g. <= 6 to < 7) rather than just <= -1 to < 0?

dmgreen added inline comments.Sep 22 2021, 1:43 AM
llvm/lib/Target/ARM/ARMTargetTransformInfo.cpp
385

Yep! I originally had it that way, but unfortunately it led to more regressions. The combiner didn't always handle the constants better to actually produce smaller code.

The 0/-1 case should be the most common, I believe, and is at least the motivating case I have.

This revision is now accepted and ready to land.Sep 28 2021, 3:35 AM
This revision was landed with ongoing or failed builds.Oct 3 2021, 11:30 AM
This revision was automatically updated to reflect the committed changes.