This is an archive of the discontinued LLVM Phabricator instance.

[AArch64][GlobalISel] Add heuristics for localizing G_CONSTANT.
ClosedPublic

Authored by aemerson on Jul 26 2022, 1:34 AM.

Details

Summary

This adds similar heuristics to G_GLOBAL_VALUE, querying the cost of
materializing a specific constant in code size. Doing so prevents us from
sinking constants which require multiple instructions to generate into
use blocks.

Code size savings on CTMark -Os:

Program                                       size.__text
                                              before         after           diff
ClamAV/clamscan                               381940.00      382052.00       0.0%
lencod/lencod                                 428408.00      428428.00       0.0%
SPASS/SPASS                                   411868.00      411876.00       0.0%
kimwitu++/kc                                  449944.00      449944.00       0.0%
Bullet/bullet                                 463588.00      463556.00      -0.0%
sqlite3/sqlite3                               284696.00      284668.00      -0.0%
consumer-typeset/consumer-typeset             414492.00      414424.00      -0.0%
7zip/7zip-benchmark                           595244.00      594972.00      -0.0%
mafft/pairlocalalign                          247512.00      247368.00      -0.1%
tramp3d-v4/tramp3d-v4                         372884.00      372044.00      -0.2%
Geomean difference                               -0.0%

Diff Detail

Event Timeline

aemerson created this revision.Jul 26 2022, 1:34 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 26 2022, 1:34 AM
aemerson requested review of this revision.Jul 26 2022, 1:34 AM
paquette added inline comments.Jul 26 2022, 11:33 AM
llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
20778

This seems like it could be a helper function in MachineRegisterInfo

(or there should be some sort of helper in STLExtras for testing if a range is at most some #elts long)

llvm/test/CodeGen/AArch64/GlobalISel/localizer-arm64-tti.ll
117

this looks like it tests the

if (RematCost == 2)
  return 2U;

path right?

what about the other two possible values for RematCost?

aemerson added inline comments.Jul 26 2022, 9:51 PM
llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
20778

Good idea.

llvm/test/CodeGen/AArch64/GlobalISel/localizer-arm64-tti.ll
117

A cost of 1 is already tested by other localizer tests. That corresponds to a constant being materializable in a single instruction, which we always localize. I'll add a test for the case of cost > 2.

aemerson updated this revision to Diff 447932.Jul 26 2022, 9:52 PM
tschuett added inline comments.
llvm/lib/CodeGen/MachineRegisterInfo.cpp
427

You could remove the braces.

This revision is now accepted and ready to land.Jul 27 2022, 10:34 AM
This revision was landed with ongoing or failed builds.Jul 27 2022, 10:51 AM
This revision was automatically updated to reflect the committed changes.