[erlang-bugs] HiPE bug with comparison of floats with integers

Kostis Sagonas kostis@REDACTED
Mon Jan 31 13:45:57 CET 2011


Paul Guyot wrote:
> Le 31 janv. 2011 à 11:20, Mikael Pettersson a écrit :
> 
>> Paul Guyot writes:
>>> Hello,
>>>
>>> There is a bug in HiPE compilation with the comparison of floats with integers.
>>> This bug happens with the following two functions:
>>>
>>> ------
>>> -module(hipe_zero).
>>> -export([f/1, g/2]).
>>>
>>> f(X) ->
>>>    Y = X / 2,
>>>    Y == 0.
>>>
>>> g(X, Z) ->
>>>    Y = X / 2,
>>>    case Z of
>>>        test when Y == 0 -> test_zero;
>>>        test -> test_non_zero;
>>>        other -> other
>>>    end.
>>> ------
>>>
>>> Beam will evaluate hipe_zero:f(0) and hipe_zero:f(0.0) to true, while HiPE will evaluate hipe_zero:f(0) and hipe_zero:f(0.0) to false. HiPE properly evaluates hipe_zero:f/1 to true if passed {icode_inline_bifs, false}. However, not inlining the '==' bif just masks the bug as HiPE does not properly evaluate hipe_zero:g(0, test) to test_zero.
>> Platform? If it's 32-bit x86, please also try 64-bit x86 (and vice-versa).
> 
> Mikael,
> 
> Thank you for your quick reply. Indeed, I should have mentioned the platform: the bug can be observed on 64-bit x86 (MacOS X and FreeBSD).

Actually, I think this information was/is irrelevant.
This is a generic bug and happens in all platforms I've tried.

Once again, the culprit seems to be the type analysis on Icode :-(
If one compiles with the [no_icode_type] option, the behavior one gets 
is that of BEAM:

12> c(hipe_zero).
{ok,hipe_zero}
13> hipe_zero:f(0).
true
14> hipe_zero:f(0.0).
true
15> hipe:c(hipe_zero).
{ok,hipe_zero}
16> hipe_zero:f(0).
false
17> hipe_zero:f(0.0).
false
18> hipe:c(hipe_zero, [no_icode_type]).
{ok,hipe_zero}
19> hipe_zero:f(0).
true
20> hipe_zero:f(0.0).
true

I will try to put it on my TODO list, but it has already overflowed.

Kostis


More information about the erlang-bugs mailing list