File 6401-beam_ssa-Optimize-dominator-calculation-again.patch of Package erlang
From 3ff39a6702b62764c92ac158b8c471390559e8f0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= <bjorn@erlang.org>
Date: Mon, 7 Feb 2022 11:51:13 +0100
Subject: [PATCH] beam_ssa: Optimize dominator calculation (again)
For the example in #5686, the time for running the `place_frames`
sub pass of `beam_ssa_pre_codegen` is reduced from about 30 seconds
to less than 20 seconds on my computer, and the time for each of
the `beam_ssa_bool` and `ssa_opt_sink` passes is almost halved.
---
lib/compiler/src/beam_ssa.erl | 18 ++++++++++++++++--
1 file changed, 16 insertions(+), 2 deletions(-)
diff --git a/lib/compiler/src/beam_ssa.erl b/lib/compiler/src/beam_ssa.erl
index 85da3b5937..2bb0870c27 100644
--- a/lib/compiler/src/beam_ssa.erl
+++ b/lib/compiler/src/beam_ssa.erl
@@ -798,9 +798,23 @@ dom_intersection_1([E1|Es1]=Set1, [E2|Es2]=Set2, Df) ->
#{E1:=Df1,E2:=Df2} = Df,
if
Df1 > Df2 ->
- dom_intersection_1(Es1, Set2, Df);
+ dom_intersection_2(Es1, Set2, Df, Df2);
Df2 > Df1 ->
- dom_intersection_1(Es2, Set1, Df); %switch arguments
+ dom_intersection_2(Es2, Set1, Df, Df1);
+ true -> %Set1 == Set2
+ %% The common suffix of the sets is the intersection.
+ Set1
+ end.
+
+dom_intersection_2([E1|Es1]=Set1, [_|Es2]=Set2, Df, Df2) ->
+ %% Blocks are numbered in the order they are found in
+ %% reverse postorder.
+ #{E1:=Df1} = Df,
+ if
+ Df1 > Df2 ->
+ dom_intersection_2(Es1, Set2, Df, Df2);
+ Df2 > Df1 ->
+ dom_intersection_2(Es2, Set1, Df, Df1); %switch arguments
true -> %Set1 == Set2
%% The common suffix of the sets is the intersection.
Set1
--
2.34.1