This is an archive of the discontinued LLVM Phabricator instance.

[FuncSpec] Estimate dead blocks more accurately.
ClosedPublic

Authored by labrinea on Aug 2 2023, 7:46 AM.

Details

Summary

Currently we only consider basic blocks with a unique predecessor when
estimating the size of dead code. However, we could expand to this to
consider blocks with a back-edge, or blocks preceded by dead blocks.

Diff Detail

Event Timeline

labrinea created this revision.Aug 2 2023, 7:46 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 2 2023, 7:46 AM
labrinea requested review of this revision.Aug 2 2023, 7:46 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 2 2023, 7:46 AM
ChuanqiXu added inline comments.Aug 2 2023, 7:34 PM
llvm/lib/Transforms/IPO/FunctionSpecialization.cpp
109–117

My instinct reaction to the function is "doesn't DeadBlocks contain DeadBB"?

So generally, when we encounter root dead blocks, then their predecessor will not be in DeadBlocks. Successors of known dead blocks do have at least one predecessor in DeadBlocks (the one we followed while traversing the graph).

llvm/lib/Transforms/IPO/FunctionSpecialization.cpp
109–117

Not yet. If isBlockExecutable and canEliminateSuccessor, then we push it to the work list. Blocks are marked dead after being popped from the work list.

158

Here, BB, which is the predecessor of SuccBB, is indeed already in DeadBlocks.

247

Here, BB corresponds to the not taken branch. If I.getParent is the predecessor of BB (despite not being in DeadBlocks), we can eliminate BB.

265

Here, Succ corresponds to the not taken branch. If I.getParent is the predecessor of Succ (despite not being in DeadBlocks), we can eliminate Succ.

ChuanqiXu accepted this revision.Aug 7 2023, 1:57 AM

LGTM with nit.

Sorry that I imaged I commented on this : (

llvm/lib/Transforms/IPO/FunctionSpecialization.cpp
109–117

Got it.

nit: Then I feel slightly better to make it a static private member function of InstCostVisitor. Then the reader may be less confused.

This revision is now accepted and ready to land.Aug 7 2023, 1:57 AM
This revision was landed with ongoing or failed builds.Aug 7 2023, 3:10 AM
This revision was automatically updated to reflect the committed changes.