This is an archive of the discontinued LLVM Phabricator instance.

[GlobalMerge] Take into account minsize attribute of global users' parents.
ClosedPublic

Authored by ab on May 26 2015, 7:12 PM.

Details

Summary

Now that we can look at users, we can trivially do this: when we would have otherwise disabled GlobalMerge (currently -O<3), we can just run it for minsize functions, as it's usually a codesize win (see attached numbers).

I'm a bit uneasy with this minsize/CodeGenOpt::Level hybrid, hence this thread; alternatives welcome. Also, minsize only for now, as we're not quite at re-enabling GM everywhere yet (see PR23579). I'm hoping that if and when we do, we can remove this code path, or turn it into cost model heuristics.

And here are some quick numbers (text section size), for -Oz {no-lto,lto}{AArch64,ARM}:




Most interesting is LTO (esp. ARM), where there's quite a few 5-15% size reductions. There aren't many regressions, a few ~1-3%.

Diff Detail

Repository
rL LLVM

Event Timeline

ab updated this revision to Diff 26567.May 26 2015, 7:12 PM
ab retitled this revision from to [GlobalMerge] Take into account minsize attribute of global users' parents..
ab updated this object.
ab edited the test plan for this revision. (Show Details)
ab added reviewers: rengolin, echristo, qcolombet.
ab set the repository for this revision to rL LLVM.
ab added a subscriber: Unknown Object (MLST).
qcolombet added inline comments.Jun 2 2015, 11:58 AM
lib/CodeGen/GlobalMerge.cpp
201 ↗(On Diff #26567)

Shouldn’t the size option affect this setting?

lib/Target/ARM/ARMTargetMachine.cpp
350 ↗(On Diff #26567)

Just for the record, a quick comment.

I am not very fond of the “if not aggressive” then do size only, but based of our offline discussion I agree this is pretty much what we do in the pass manager when creating other passes (like loop unswitch).

Anyhow, I do not have a better alternative.

test/CodeGen/AArch64/global-merge-ignore-single-use-minsize.ll
39 ↗(On Diff #26567)

In the previous test case, you have a clear separation between the globals used in minsize functions and the ones used in non-minsize function.

Could you make another test case that mixes both?
I.e.,
G1
G2
G3

minsizefunc {
G1
G3
}

non-minsizefunc {
G1
G2
}

ab added inline comments.Jun 3 2015, 7:06 PM
lib/CodeGen/GlobalMerge.cpp
201 ↗(On Diff #26567)

I'm not sure how, because without users, there's no minsize attribute to look at.

It shouldn't matter anyway, as this is mostly an option for testing (to get the old GlobalMerge behavior back).

lib/Target/ARM/ARMTargetMachine.cpp
350 ↗(On Diff #26567)

I don't like it either, but I also couldn't come up with a better way ;)

test/CodeGen/AArch64/global-merge-ignore-single-use-minsize.ll
39 ↗(On Diff #26567)

Done.

ab updated this revision to Diff 27084.Jun 3 2015, 7:07 PM
ab removed rL LLVM as the repository for this revision.
  • Add mixed minsize/non-minsize user functions
qcolombet accepted this revision.Jun 4 2015, 10:14 AM
qcolombet edited edge metadata.

Hi Ahmed,

LGTM.

Thanks,
-Quentin

This revision is now accepted and ready to land.Jun 4 2015, 10:14 AM
This revision was automatically updated to reflect the committed changes.
ab added a comment.Jun 4 2015, 1:45 PM

Thanks Quentin, r239087.

For the record, I also changed the OnlyOptimizeForSize -O<3 check to be overridden by the debugging flags (-aarch64/-arm-global-merge), to keep it easy to get the "just enable GM" behavior.

-Ahmed