File 5121-beam_ssa-Optimize-dominator-calculation.patch of Package erlang
From 33112e74a97ee877eb54a9f54ed01c059cf36965 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= <bjorn@erlang.org>
Date: Thu, 20 Jan 2022 08:43:05 +0100
Subject: [PATCH 1/2] beam_ssa: Optimize dominator calculation
Optimize functions with a huge number of blocks where all blocks are
dominated by block 0. This optimization will make the
`beam_ssa_pre_codegen` pass run more than twice as fast for the
example in #5140.
While at it, clean up indentation in `dom_intersection_1/3`.
---
lib/compiler/src/beam_ssa.erl | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/lib/compiler/src/beam_ssa.erl b/lib/compiler/src/beam_ssa.erl
index e2688b7fa9..85da3b5937 100644
--- a/lib/compiler/src/beam_ssa.erl
+++ b/lib/compiler/src/beam_ssa.erl
@@ -785,6 +785,9 @@ dom_intersection([S], _Df) ->
dom_intersection([S|Ss], Df) ->
dom_intersection(S, Ss, Df).
+dom_intersection([0]=S, [_|_], _Df) ->
+ %% No need to continue. (We KNOW that all sets end in [0].)
+ S;
dom_intersection(S1, [S2|Ss], Df) ->
dom_intersection(dom_intersection_1(S1, S2, Df), Ss, Df);
dom_intersection(S, [], _Df) -> S.
@@ -793,11 +796,12 @@ dom_intersection_1([E1|Es1]=Set1, [E2|Es2]=Set2, Df) ->
%% Blocks are numbered in the order they are found in
%% reverse postorder.
#{E1:=Df1,E2:=Df2} = Df,
- if Df1 > Df2 ->
+ if
+ Df1 > Df2 ->
dom_intersection_1(Es1, Set2, Df);
- Df2 > Df1 ->
- dom_intersection_1(Es2, Set1, Df); %switch arguments!
- true -> %Set1 == Set2
+ Df2 > Df1 ->
+ dom_intersection_1(Es2, Set1, Df); %switch arguments
+ true -> %Set1 == Set2
%% The common suffix of the sets is the intersection.
Set1
end.
--
2.31.1