[erlang-patches] [HiPE] fix fconv translation and fmove generation

Mikael Pettersson mikpelinux@REDACTED
Thu Jan 8 20:28:55 CET 2015


The following test case crashes the HiPE compiler on all targets except ARM:

==snip==
-module(trivial_13).
-export([test/0]).
test() -> return_it(42).
return_it(X) -> R = (2 * X) / 2, round(R).
==snip==

This actually triggers two independent bugs:

RTL produces an #fconv{} instruction with an immediate operand, but the
backends unconditionally access the operand as a temporary.  This results
in broken representation in the backends and eventually they crash.  In
this case, the bug is in the backends.

The backends must check for immediate operands in #fconv{} and translate
them accordingly for their respective targets.

With the above fixed the backends still crash, generally with complaints
about inconsistent and/or incomplete register allocation.  This happens
because hipe_rtl:phi_remove_pred/2 produces a #move{} instruction with
floating-point temporaries as operands, even though such moves MUST be
#fmove{} instructions.

This is fixed by updating phi_remove_pred/2 to check for and handle
floating-point moves.  I also added type checks to the #move{} and #fmove{}
constructor and setter functions to ensure that similar mishaps cannot
happen again.

Tested with the HiPE test suite on x86_64, sparc64 (32-bit), and powerpc64
(32-bit): fixes the test case with no new failures.  The ARM backend is
still "soft-float" and not affected by these problems.

(This test case has actually been in the HiPE test suite for a long time,
but it didn't fail because it was compiled in single-MFA mode (only
return_it/1 was compiled), limiting the effectiveness of interprocedural
optimizations.  That mode was removed some time ago (R15?), and compiling
the test case in whole-module mode exposed the problems.)

Signed-off-by: Mikael Pettersson <mikpelinux@REDACTED>

Links:

git fetch git://github.com/mikpe/otp.git hipe-fconv-fmove-fixes

https://github.com/mikpe/otp/compare/erlang:maint...hipe-fconv-fmove-fixes
https://github.com/mikpe/otp/compare/erlang:maint...hipe-fconv-fmove-fixes.patch

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



More information about the erlang-patches mailing list