Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 23 additions & 9 deletions lib/compiler/src/beam_ssa_bool.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1040,15 +1040,11 @@ ensure_no_failing_instructions(First, Second, G, St) ->

can_fail({succeeded,_}, V, G) -> not eaten_by_phi(V, G);
can_fail(put_map, _, _) -> true;
can_fail(_, _, _) -> false.

eaten_by_phi(V, G) ->
{br,_,Fail} = get_targets(V, G),
case beam_digraph:vertex(G, Fail) of
br ->
[To] = beam_digraph:out_neighbours(G, Fail),
case beam_digraph:vertex(G, To) of
#b_set{op=phi} ->
can_fail(_, V, G) ->
case get_targets(V, G) of
{br,_Succ,Fail} ->
case follow_branch(G, Fail) of
{external,_} ->
true;
_ ->
false
Expand All @@ -1057,6 +1053,24 @@ eaten_by_phi(V, G) ->
false
end.

eaten_by_phi(V, G) ->
{br,_,Fail} = get_targets(V, G),
case follow_branch(G, Fail) of
#b_set{op=phi} ->
true;
_ ->
false
end.

follow_branch(G, Br) ->
case beam_digraph:vertex(G, Br) of
br ->
[To] = beam_digraph:out_neighbours(G, Br),
beam_digraph:vertex(G, To);
_ ->
none
end.

%% order_args([Arg1,Arg2], G, St) -> {First,Second}.
%% Order arguments for a boolean operator so that there is path in the
%% digraph from the instruction referered to by the first operand to
Expand Down
12 changes: 12 additions & 0 deletions lib/compiler/test/guard_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -2621,6 +2621,7 @@ beam_bool_SUITE(_Config) ->
gh_7252(),
gh_7339(),
gh_7370(),
gh_7517(),
ok.

before_and_inside_if() ->
Expand Down Expand Up @@ -3216,6 +3217,17 @@ gh_7370(A) when (not (not is_float(A))) =/= ((ok and ok) or true) ->
gh_7370(_) ->
b.

gh_7517() ->
ok = catch do_gh_7517([]),
ok = catch do_gh_7517([a,b,c]),
{'EXIT',{function_clause,_}} = catch do_gh_7517(ok),
{'EXIT',{function_clause,_}} = catch do_gh_7517(<<>>),
ok.

do_gh_7517(A) when (ok /= A) or is_float(is_list(A) orelse ok andalso ok) ->
ok.


%%%
%%% End of beam_bool_SUITE tests.
%%%
Expand Down