diff options
author | Björn Gustavsson <bjorn@erlang.org> | 2019-09-19 14:20:30 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-09-19 14:20:30 +0200 |
commit | aeb981bcf48be40027e5332831026dd440daf348 (patch) | |
tree | c10e6501988ae92093ab8174b38c4b02dde37966 /lib/compiler/test/andor_SUITE.erl | |
parent | 43d8e4299d49141bab2d1145de64c3593252b073 (diff) | |
parent | 148567a6b9258ae74138566c9109d348b1768583 (diff) | |
download | erlang-aeb981bcf48be40027e5332831026dd440daf348.tar.gz |
Merge pull request #2387 from bjorng/bjorn/compiler/bool-opt
Move guard optimizations from v3_kernel to a new beam_ssa_bool pass
Diffstat (limited to 'lib/compiler/test/andor_SUITE.erl')
-rw-r--r-- | lib/compiler/test/andor_SUITE.erl | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/lib/compiler/test/andor_SUITE.erl b/lib/compiler/test/andor_SUITE.erl index 5c463063c1..7232eb0ffd 100644 --- a/lib/compiler/test/andor_SUITE.erl +++ b/lib/compiler/test/andor_SUITE.erl @@ -66,6 +66,17 @@ t_case(Config) when is_list(Config) -> true = (catch t_case_e({a,b}, {a,b})), false = (catch t_case_e({a,b}, 42)), + {true,false} = t_case_f1(true, pos), + {false,true} = t_case_f1(true, whatever), + {false,true} = t_case_f1(false, pos), + {false,true} = t_case_f1(false, whatever), + {false,false} = t_case_f1(not_boolean, pos), + {false,false} = t_case_f1(not_boolean, whatever), + + false = t_case_f2(true), + true = t_case_f2(false), + false = t_case_f2(whatever), + true = t_case_xy(42, 100, 700), true = t_case_xy(42, 100, whatever), false = t_case_xy(42, wrong, 700), @@ -109,6 +120,25 @@ t_case_e(A, B) -> Bool when is_tuple(A) -> id(Bool) end. +t_case_f1(IsInt, Eval) -> + B = case IsInt of + true -> Eval =:= pos; + false -> false; + _ -> IsInt + end, + + %% The above is the same as `IsInt andalso Eval =:= pos` in a guard. + %% In a real guard, variable `B` will only be used once. + {B =:= true, B =:= false}. + +t_case_f2(IsInt) -> + B = case IsInt of + true -> false; + false -> true; + _ -> IsInt + end, + B =:= true. + t_case_xy(X, Y, Z) -> Res = t_case_x(X, Y, Z), Res = t_case_y(X, Y, Z). |