diff options
author | Björn Gustavsson <bjorn@erlang.org> | 2019-10-29 13:07:30 +0100 |
---|---|---|
committer | Björn Gustavsson <bjorn@erlang.org> | 2019-12-11 13:28:25 +0100 |
commit | 2a93217fccf088a1c14f8bd6ac71a01c170ffa3f (patch) | |
tree | ecbd6442500c8c9271f8a6e796df006862f22ead | |
parent | 3f435b8ae02ee3c9d64d4b955115caf2a2ebb1c7 (diff) | |
download | erlang-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.erl | 3 | ||||
-rw-r--r-- | lib/compiler/test/receive_SUITE_data/ref_opt/yes_17.erl | 14 | ||||
-rw-r--r-- | lib/compiler/test/receive_SUITE_data/ref_opt/yes_18.erl | 15 |
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. |