File 2623-Optimize-move-swap-combination.patch of Package erlang

From 2ec9e4851949d9367f2d8d879c3f75f9747d7d6a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= <bjorn@erlang.org>
Date: Sat, 10 Dec 2022 17:11:22 +0100
Subject: [PATCH 3/4] Optimize move / swap combination

Some combinations of `move` followed by `swap` can be replaced
with two `move` instructions, which should be somewhat cheaper.
---
 lib/compiler/src/beam_block.erl | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/lib/compiler/src/beam_block.erl b/lib/compiler/src/beam_block.erl
index 2954d95b7e..b93293763d 100644
--- a/lib/compiler/src/beam_block.erl
+++ b/lib/compiler/src/beam_block.erl
@@ -74,6 +74,10 @@ function({function,Name,Arity,CLabel,Is0}) ->
 %%% (Provided that x2 is killed in the code that follows.)
 %%%
 
+swap_opt([{move,Src,Dst},{swap,Dst,Other}|Is]) when Src =/= Other ->
+    swap_opt([{move,Other,Dst},{move,Src,Other}|Is]);
+swap_opt([{move,Src,Dst},{swap,Other,Dst}|Is]) when Src =/= Other ->
+    swap_opt([{move,Other,Dst},{move,Src,Other}|Is]);
 swap_opt([{move,Reg1,{x,_}=Temp}=Move1,
           {move,Reg2,Reg1}=Move2|Is0]) when Reg1 =/= Temp ->
     case swap_opt_end(Is0, Temp, Reg2, []) of
-- 
2.35.3

openSUSE Build Service is sponsored by