[CodeGen] Limit mem ops checks count for reasonable compilation speed #147151
+30
−1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
We've got a ~5 hours compilation of HistogramGIFFTMap.cpp file from Firefox project for the custom out-of-tree backend. Time-consuming part is an analysis of thounsand of memory instructions with thousands of memory operands each.
Proposed fix is to limit checks count for memory operands where it is possible to fallback to conservative answer. After fix applied compilation takes ~0.3 sec.
Details:
It happens in huge switch construction with ~1000 cases. The root cause is an interaction of
BranchFolder
optimization called inside post-raIfCovnerter
pass andMachineBlockPlacement
pass:BranchFolder
extracts identical store instruction into block from its predecessors (~ 1000 predecessors).MachineBlockPlacement
pass makes a decision to tail merge such instructions back into predecessors. So, MIR contains ~1000 blocks with store instructions, each one contains ~1000 memory operands.After that, analysis of memory instructions becomes really time-consuming.
In MIR it looks like the following.
MIR before
IfConverter
:After
BranchFolder
run fromIfConverter
:And after
MachineBlockPlacement
pass:Seems like the issue is related only to backends which uses post-ra
IfConverter
pass. It affects PowerPC, Hexagon, SystemZ and AMDGPU.We would like to share fix with community if it is ok.