[erlang-questions] HiPE miscompilation of binary matches
Andreas Schultz
aschultz@REDACTED
Wed Nov 2 11:23:14 CET 2016
Hi,
Either HiPE is messing up binary matches in some cases or I'm not seeing the problem.
A reduced version of the code is:
-module(binopt).
-export([test1/1, test2/1, data/0]).
-compile([bin_opt_info]).
data() -> <<50,16,0>>.
test1(<<1:3, 1:1, _:1, 0:1, 0:1, 0:1, _/binary>>) ->
'Case #1';
test1(<<1:3, 1:1, _:1, _:1, _:1, _:1, _/binary>>) ->
'Case #2';
test1(_) ->
other.
test2(<<1:3, 1:1, _:1, A:1, B:1, C:1, _/binary>>)
when A =:= 1; B =:= 1; C =:= 1 ->
'Case #2';
test2(<<1:3, 1:1, _:1, 0:1, 0:1, 0:1, _/binary>>) ->
'Case #1';
test2(_) ->
other.
With Erlang 19.1.3 the HiPE compile version of this behaves differently than the non-HiPE version:
Erlang/OTP 19 [erts-8.1] [source] [64-bit] [smp:8:8] [async-threads:10] [hipe] [kernel-poll:false]
Eshell V8.1 (abort with ^G)
1> compile:file("src/binopt", [native, {hipe, o3}]).
{ok,binopt}
2> binopt:test1(binopt:data()).
other
WTF???? Case #2 in test1 should match and I can't see why it shouldn't.
3> binopt:test2(binopt:data()).
'Case #2'
This is as expected.
None HiPE:
4> compile:file("src/binopt", []).
{ok,binopt}
6> l(binopt).
{module,binopt}
7> binopt:test1(binopt:data()).
'Case #2'
8> binopt:test2(binopt:data()).
'Case #2'
As expected, both version return the same result.
So, do I do something wrong here or is this a legitimate HiPE bug?
Andreas
More information about the erlang-questions
mailing list