HiPE miscompilation of binary matches

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

HiPE miscompilation of binary matches

Andreas Schultz
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
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: HiPE miscompilation of binary matches

Kostis Sagonas-2
On 11/02/2016 11:23 AM, Andreas Schultz wrote:
> So, do I do something wrong here or is this a legitimate HiPE bug?

Yes, this looks looks like a legitimate HiPE bug.  Will investigate.

Kostis
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: HiPE miscompilation of binary matches

Kostis Sagonas-2
On 11/02/2016 12:06 PM, Kostis Sagonas wrote:
> On 11/02/2016 11:23 AM, Andreas Schultz wrote:
>> So, do I do something wrong here or is this a legitimate HiPE bug?
>
> Yes, this looks looks like a legitimate HiPE bug.  Will investigate.

Apologies for replying to my own mail, but we indeed investigated this
and a fix appears here:

   https://github.com/erlang/otp/pull/1234

I guess it will be merged to maint at some point and the fix will appear
in a released OTP, hopefully soon.

Thanks for reporting this bug.

Kostis
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions