File 0245-ErLLVM-Preserve-precise-BEAM-tailcall-semantics.patch of Package erlang

From 970261b5384bd55abdcbf55bd4a75a3c26a0bda8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Magnus=20L=C3=A5ng?= <margnus1@telia.com>
Date: Fri, 19 Jan 2018 16:05:52 +0100
Subject: [PATCH] ErLLVM: Preserve precise BEAM tailcall semantics

The BEAM compiler chooses not to perform tailcall optimisations for some
calls in tail position, for example to some built-in functions. However,
when the ErLLVM HiPE backend is used, LLVM may choose to perform
tailcall optimisation on these calls, breaking the expected semantics.

To preserve the precise semantics exhibited by BEAM, the 'notail'
marker, present in LLVM since version 3.8, is added to call instructions
that BEAM has not turned into tail calls, which inhibits LLVM from
performing tail-call optimisation in turn.
---
 lib/hipe/llvm/hipe_llvm.erl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/hipe/llvm/hipe_llvm.erl b/lib/hipe/llvm/hipe_llvm.erl
index 641d3fda0a..e04b171194 100644
--- a/lib/hipe/llvm/hipe_llvm.erl
+++ b/lib/hipe/llvm/hipe_llvm.erl
@@ -934,7 +934,7 @@ pp_ins(Dev, Ver, I) ->
       end,
       case call_is_tail(I) of
         true -> write(Dev, "tail ");
-        false -> ok
+        false -> write(Dev, "notail ")
       end,
       write(Dev, ["call ", call_cconv(I), " "]),
       pp_options(Dev, call_ret_attrs(I)),
-- 
2.16.0

openSUSE Build Service is sponsored by