LSL-PyOptimizer icon indicating copy to clipboard operation
LSL-PyOptimizer copied to clipboard

Dead Code Removal does not remove all dead code

Open KrsityKu opened this issue 1 year ago • 0 comments

Example code:

default
{
	link_message(integer sender, integer num, string str, key keyVal)
	{
		integer dead = 0;
		if (num == 5)
			dead = 1;
		else
			dead = 2;
		llOwnerSay("Not Dead");
	}
}

Output with DCR + Constant Folding:

default
{
    link_message(integer sender, integer num, string str, key keyVal)
    {
        num == 5;
        llOwnerSay("Not Dead");
    }
}

Without constant folding it is even worse:

default
{
    link_message(integer sender, integer num, string str, key keyVal)
    {
        0;
        if (num == 5)
            1;
        else
            2;
        llOwnerSay("Not Dead");
    }
}

Re-running the output code back through the optimizer will remove the dead code (with Const folding on).

Expected Output:

default
{
    link_message(integer sender, integer num, string str, key keyVal)
    {
        llOwnerSay("Not Dead");
    }
}

KrsityKu avatar Feb 17 '24 09:02 KrsityKu