Skip to content

Conversation

@andmadri
Copy link

Most of the optimizations are in recursiveVisit() and splitIntoSCCs(). Optimized splitIntoSCCs when blocks size was one, there was no need to split into SCC as that is pretty costly. I aslo find a way to exit earlier rather than alwasy looping a 100 times until we decide to give up on a SCC.

@andmadri andmadri requested a review from yuri91 December 22, 2025 13:45
@andmadri andmadri force-pushed the type-optimizer-changes branch from 90981f4 to a97fa00 Compare January 5, 2026 14:07
Copy link
Member

@yuri91 yuri91 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.
I would appreciate a second look from @alexp-sssup to a2bf1af specifically.
It's the only actual change to the algorithm.

@alexp-sssup
Copy link
Member

@yuri91 @andmadri I think the logic is not aggressive enough, specifically there is no point in iterating for a few times to decide the improvements have stalled. If the logic is sound it should be equivalent to stop immediately. Could we validate if there is ever any case where progress is made in a second iteration after the first has not made any?

@andmadri andmadri force-pushed the type-optimizer-changes branch 3 times, most recently from b80cfd9 to 2ac6f3f Compare January 13, 2026 20:20
@andmadri andmadri requested a review from alexp-sssup January 14, 2026 09:04
};
llvm::Function& F;
std::vector<std::pair<llvm::BasicBlock*, llvm::BasicBlock*>> existingEdges;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit, avoid spurious changes

for (llvm::BasicBlock* succ : visitNext)
registerEdge(start, succ);

if (parentNode)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find this logic somewhat confusing, although I don't recall exactly how recursion works here. Two things.

  1. I think the std::stack object here is redundant, you could use just a flag per SCC. Moreover, do we even need to store it in parentNode? Could we return it from each children in recursiveVisit?

  2. Doing the check here is counterintuitive, it should be hoisted and done in the context of the parent rather than doing it in the context of the children using parentNode.

@yuri91 for further feedback

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A flag could work but I don't think we can return it from each children in recursiveVisit because of how the recursion works. The issue is that when we reach the last child and it loops back to itself, the recursion doesn’t unwind to the parent. Instead, we recurse again from that child, as that child has the same SCC set. That is why I am checking the flag/stack at that point. Either we decide to continue recursing through that set of the same SCCs until we hit the iteration limit or we resolve it, or we return to the parent and move on.

@andmadri andmadri force-pushed the type-optimizer-changes branch 4 times, most recently from cd0499d to f89fb50 Compare January 15, 2026 10:54
The parent tracks whether progress has been made while processing its SCC set.

Each visit to a child SCC returns a boolean indicating whether running that child
resulted in progress. Children are visited in reverse order.

The last child is always the starting SCC. The first child is a copy that contains
all basic blocks split into SCCs and used to detect loops. This copy is marked
reachable when, during edge registration, we detect a back-edge into the current SCC set.

If the copy is reachable, the SCC set forms a loop. After all SCCs have ben analyzed,
we use the progress flag to decide whether to visit the copy again. If progress was made,
the copy is visited, which recreates the same SCC structure with a new copy at the end.
If no progress was made, we stop recursing that set of SCC and mark them as skipped.
@andmadri andmadri force-pushed the type-optimizer-changes branch from f89fb50 to e0cfe14 Compare January 15, 2026 10:57
@yuri91 yuri91 added the hydra Run hydra on this PR label Jan 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

hydra Run hydra on this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants