From 8052922d105d236c6cf071333107181fc82c191d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= <bjorn@erlang.org>
Date: Mon, 24 Oct 2016 06:32:20 +0200
Subject: Don't let inline_list_funcs degrade optimizations

83199af0263 refactored sys_core_fold to break out the code for the
inline_lists_funcs option to its own module. Unfortunately, it also
accidentally turned off compile-time evaluation of calls to BIFs with
wholly or partial constant arguments.

For example, the code for the following funtion gets much worse
when inline_list_funcs is used:

b() ->
    R0 = #r{},
    R1 = setelement(1+2, R0, "deux"),
    R2 = setelement(1+3, R1, "trois"),
    R3 = setelement(1+5, R2, "cinq"),
    R4 = setelement(1+2, R3, "DEUX"),
    R4.

ERL-285
---
 lib/compiler/src/sys_core_fold.erl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

(limited to 'lib')

diff --git a/lib/compiler/src/sys_core_fold.erl b/lib/compiler/src/sys_core_fold.erl
index 08b02101a6..5e1602cb5b 100644
--- a/lib/compiler/src/sys_core_fold.erl
+++ b/lib/compiler/src/sys_core_fold.erl
@@ -734,7 +734,7 @@ call(#c_call{args=As}=Call, #c_literal{val=M}=M0, #c_literal{val=N}=N0, Sub) ->
   	false ->
 	    case sys_core_fold_lists:call(Call, M, N, As) of
 		none ->
-		    call_1(Call, M, N, As, Sub);
+		    call_1(Call, M0, N0, As, Sub);
 		Core ->
 		    expr(Core, Sub)
 	    end
-- 
cgit v1.2.3