This is an archive of the discontinued LLVM Phabricator instance.

[ThinLTO] Compile time improvement to propagateAttributes
ClosedPublic

Authored by tejohnson on Jul 30 2020, 2:46 PM.

Details

Summary

I found that propagateAttributes was ~23% of a thin link's run time
(almost 4x higher than the second hottest function). The main reason is
that it re-examines a global var each time it is referenced. This
becomes unnecessary once it is marked both non read only and non write
only. I added a set to avoid doing redundant work, which dropped the
runtime of that thin link by almost 15%.

I made a smaller efficiency improvement (no measurable impact) to skip
all summaries for a VI if the first copy is dead. I added an assert to
ensure that all copies are dead if any is. The code in
computeDeadSymbols marks all summaries for a VI as live. There is one
corner case where it was skipping marking an alias as live, that I
fixed. However, since the code earlier marked all copies of a preserved
GUID's VI as live, and each 'visit' marks all copies live, the only case
where this could make a difference is summaries that were marked live
when they were built initially, and that is only a few special compiler
generated symbols and inline assembly symbols, so it likely is never
provoked in practice.

Diff Detail

Event Timeline

tejohnson created this revision.Jul 30 2020, 2:46 PM
tejohnson requested review of this revision.Jul 30 2020, 2:46 PM
evgeny777 added a comment.EditedJul 31 2020, 5:43 AM

I made a smaller efficiency improvement (no measurable impact) to skip all summaries for a VI if the first copy is dead. I added an assert to ensure that all copies are dead if any is....

Will this work correctly in case of GUID collision? (see https://reviews.llvm.org/D67322)
BTW, what's the maximum performance improvement you got in absolute values?

llvm/lib/IR/ModuleSummaryIndex.cpp
179

nit: you can check for !VI.getAccessSpecifier() here and probably refactor the assertion above

I made a smaller efficiency improvement (no measurable impact) to skip all summaries for a VI if the first copy is dead. I added an assert to ensure that all copies are dead if any is....

Will this work correctly in case of GUID collision? (see https://reviews.llvm.org/D67322)

The code in computeDeadSymbols will conservatively mark all copies live if any is. See not only the worklist iteration I modified here, but also the code in visit at lines 878-879, and the preserved GUID handling at lines 814-815. So if there is a collision, the colliding values may conservatively be marked live, so the loop in propagateAttributes will handle them. I.e they are either all dead or all live (especially after my fix here which will make the behavior more conservative in the chance case of any alias values that collide with a value marked live during module summary building). Other than the corner case I'm fixing here, this should be a no-op in behavior for that loop in propagateAttributes, which was already skipping all dead values, and which does check if it is a GlobalVarSummary already.

BTW, what's the maximum performance improvement you got in absolute values?

In a large binary build I saw this shave off ~10-11s in a ~71s thin link.

llvm/lib/IR/ModuleSummaryIndex.cpp
179

Will change the check here. Not sure what you want me to do with the assert though? There's not a convenient else below to put an assertion that just checks the isa<> when the access specifier is null, since it is an else if.

tejohnson updated this revision to Diff 282238.Jul 31 2020, 9:02 AM

Address comment

evgeny777 accepted this revision.Jul 31 2020, 9:56 AM

The code in computeDeadSymbols will conservatively mark all copies live if any is. See not only the worklist iteration I modified here, but also the code in visit at lines 878-879, and the preserved GUID handling at lines 814-815. So if there is a collision, the colliding values may conservatively be marked live, so the loop in propagateAttributes will handle them. I.e they are either all dead or all live (especially after my fix here which will make the behavior more conservative in the chance case of any alias values that collide with a value marked live during module summary building). Other than the corner case I'm fixing here, this should be a no-op in behavior for that loop in propagateAttributes, which was already skipping all dead values, and which does check if it is a GlobalVarSummary already.

Ok, got it. My understanding is that collision still may happen between internal module asm symbol (because those have Live = true after analysis) and some other internal symbol with the same name (and module name) which is computed dead. This is rather unlikely to happen in reality, but please leave a comment about this before assertion. That said LGTM.

llvm/lib/IR/ModuleSummaryIndex.cpp
179

Ah, ok. Let's leave assert where it is.

This revision is now accepted and ready to land.Jul 31 2020, 9:56 AM

The code in computeDeadSymbols will conservatively mark all copies live if any is. See not only the worklist iteration I modified here, but also the code in visit at lines 878-879, and the preserved GUID handling at lines 814-815. So if there is a collision, the colliding values may conservatively be marked live, so the loop in propagateAttributes will handle them. I.e they are either all dead or all live (especially after my fix here which will make the behavior more conservative in the chance case of any alias values that collide with a value marked live during module summary building). Other than the corner case I'm fixing here, this should be a no-op in behavior for that loop in propagateAttributes, which was already skipping all dead values, and which does check if it is a GlobalVarSummary already.

Ok, got it. My understanding is that collision still may happen between internal module asm symbol (because those have Live = true after analysis) and some other internal symbol with the same name (and module name) which is computed dead. This is rather unlikely to happen in reality, but please leave a comment about this before assertion. That said LGTM.

I'll add a comment. The collision may still happen, but the in reality dead symbol will conservatively have been marked live by computeDeadSymbols.

Improve comment

This revision was landed with ongoing or failed builds.Jul 31 2020, 10:54 AM
This revision was automatically updated to reflect the committed changes.