summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjörn Gustavsson <bjorn@erlang.org>2019-10-29 13:07:30 +0100
committerBjörn Gustavsson <bjorn@erlang.org>2019-12-11 13:28:25 +0100
commit2a93217fccf088a1c14f8bd6ac71a01c170ffa3f (patch)
treeecbd6442500c8c9271f8a6e796df006862f22ead
parent3f435b8ae02ee3c9d64d4b955115caf2a2ebb1c7 (diff)
downloaderlang-2a93217fccf088a1c14f8bd6ac71a01c170ffa3f.tar.gz
beam_ssa_recv: Optimize receives with an 'after 0' clause
This used to be optimized before OTP 22.
-rw-r--r--lib/compiler/src/beam_ssa_recv.erl3
-rw-r--r--lib/compiler/test/receive_SUITE_data/ref_opt/yes_17.erl14
-rw-r--r--lib/compiler/test/receive_SUITE_data/ref_opt/yes_18.erl15
3 files changed, 32 insertions, 0 deletions
diff --git a/lib/compiler/src/beam_ssa_recv.erl b/lib/compiler/src/beam_ssa_recv.erl
index 31b8460525..767242d1e5 100644
--- a/lib/compiler/src/beam_ssa_recv.erl
+++ b/lib/compiler/src/beam_ssa_recv.erl
@@ -259,6 +259,9 @@ opt_ref_used_is([#b_set{op=call,
Vs = update_vars(I, Vs0),
opt_ref_used_is(Is, Vs)
end;
+opt_ref_used_is([#b_set{op=timeout}|_], _Vs) ->
+ %% Handle "after 0"; wait_timeout has been optimized away.
+ done;
opt_ref_used_is([#b_set{}=I|Is], Vs0) ->
Vs = update_vars(I, Vs0),
opt_ref_used_is(Is, Vs);
diff --git a/lib/compiler/test/receive_SUITE_data/ref_opt/yes_17.erl b/lib/compiler/test/receive_SUITE_data/ref_opt/yes_17.erl
new file mode 100644
index 0000000000..421ed825c6
--- /dev/null
+++ b/lib/compiler/test/receive_SUITE_data/ref_opt/yes_17.erl
@@ -0,0 +1,14 @@
+-module(yes_17).
+-export([?MODULE/0,f/0]).
+
+?MODULE() ->
+ ok.
+
+f() ->
+ Ref = make_ref(),
+ receive
+ {Ref,Reply} ->
+ Reply
+ after 0 ->
+ ok
+ end.
diff --git a/lib/compiler/test/receive_SUITE_data/ref_opt/yes_18.erl b/lib/compiler/test/receive_SUITE_data/ref_opt/yes_18.erl
new file mode 100644
index 0000000000..92135f53f4
--- /dev/null
+++ b/lib/compiler/test/receive_SUITE_data/ref_opt/yes_18.erl
@@ -0,0 +1,15 @@
+-module(yes_18).
+-export([?MODULE/0,f/2]).
+
+?MODULE() ->
+ ok.
+
+f(Pid, Msg) ->
+ Ref = make_ref(),
+ Pid ! Msg,
+ receive
+ {Ref,Reply} ->
+ Reply
+ after 0 ->
+ ok
+ end.