dotgnu-libjit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Libjit-developers] libjit: 2 + 2 = 3


From: Aleksey Demakov
Subject: [Libjit-developers] libjit: 2 + 2 = 3
Date: Sat, 24 Dec 2005 13:48:30 +0600

Hi all,

I found a problem that seems to be a bug or perhaps a serious flaw
in the libjit register allocation mechanism.

The attached file contains a test case for the problem. It performs
a simple calcualtion the result of which has to be equal to 4 but
libjit returns 3.

This is the core part of the test:

    /* value1 = 1 */
    jit_insn_store(function, value1, one);
    /* value1 = value1 + 1  =>  value1 = 2 */
    jit_insn_store(function, value1, jit_insn_add(function, value1, one));
    /* value2 = value1 + value1  =>  value2 = 4 */
    jit_insn_store(function, value2, jit_insn_add(function, value1, value1));
    jit_insn_return(function, value2);

A long gdb session revealed the following.

Before the last addition libjit keeps value1 which just has been incremented
in a register. The libjit liveness analysis concludes that value1 is not used
after this point.

The function _jit_regs_load_value is called twice for the same value. On the
first call it finds the register that contains the right value checks
if it is used
again and wrongly thinking that it is not it disassociates the register with the
value and marks it as a temporary without spilling it. On the second call it
cannot find the right register and loads the obsolete value from the frame.
So in the end it does 2 + 1 instead of 2  + 2.

Regards,
Aleksey

Attachment: tr.c
Description: Text Data


reply via email to

[Prev in Thread] Current Thread [Next in Thread]