This is an archive of the discontinued LLVM Phabricator instance.

[DAGCombiner] Limit graph traversal to cap compile times
ClosedPublic

Authored by pranavk on Jul 10 2023, 1:30 PM.

Details

Summary

hasPredecessorHelper method, that is used by DAGCombiner to combine to pre-indexed and post-indexed load/stores, is a major source of slowdown while compiling a large function with MSan enabled on Arm. This patch caps the DFS-graph traversal for this method to 8192 which cuts compile time by 50% (4m -> 2m compile time) at the cost of less overall nodes combined.

Here's the summary of pre-index DAG nodes created and time it took to compile the pathological case with different MaxDepth limit:

  1. With MaxDepth = 0 (unlimited): 1800, took 4m
  2. With MaxDepth = 32k, 560, took 2m31s
  3. With MaxDepth = 8k, 139, took 2m.

Diff Detail

Event Timeline

pranavk created this revision.Jul 10 2023, 1:30 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 10 2023, 1:30 PM
Herald added a subscriber: hiraditya. · View Herald Transcript
pranavk requested review of this revision.Jul 10 2023, 1:30 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 10 2023, 1:30 PM
pranavk edited the summary of this revision. (Show Details)Jul 10 2023, 1:40 PM
pranavk added reviewers: MaskRay, echristo.
pranavk edited the summary of this revision. (Show Details)Jul 10 2023, 2:14 PM
MaskRay added a comment.EditedJul 10 2023, 2:34 PM

(We use a MaxDepth pattern in many places, e.g., llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp, several *ISelLowering.cpp files, and SelectionDAG::copyExtraInfo.)

It seems that most hasPredecessorHelper callers don't set Max, and only a few set Max.

I am curious whether you can come up a pathological case to demonstrate the issue, even if crafting a test is not so practical. Without more information future refactors cannot know how they can be certain this problem has been fixed in the root cause (if there is a way...).

rnk added a subscriber: rnk.

I think Alina had some context with previous DAG combine compile time problems.

pranavk edited the summary of this revision. (Show Details)Jul 24 2023, 9:55 AM
MaskRay accepted this revision.Jul 24 2023, 10:07 AM

I think this is reasonable. We also use a threshold argument in some other places where hasPredecessorHelper is used, e.g. SelectionDAGISel.cpp 8192.

This revision is now accepted and ready to land.Jul 24 2023, 10:07 AM
dblaikie added inline comments.
llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
17669
17888
pranavk updated this revision to Diff 544031.Jul 25 2023, 10:31 AM

clang-format and reviewer suggestions

llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
17669

Thanks. I made it a constexpr. I think I made it 'const unsigned' after looking at similar code in this file or directory.

This revision was automatically updated to reflect the committed changes.