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

Constant folding does not work when variable is used in multiple vectors

Open KrsityKu opened this issue 1 year ago • 0 comments

In the following code:

default
{
	touch_start(integer total_number)
	{
		float val = 1.0;
		vector vec1 = <val + val, 0, 0>;
		vector vec2 = <val + val, 0, 0>;
		llOwnerSay((string)vec1);
		llOwnerSay((string)vec2);
	}

	touch_end(integer total_number)
	{
		float val = 1.0;
		vector vec1 = <val + val, 0, 0>;
		llOwnerSay((string)vec1);
	}
}

touch_start does not fully fold the constants:

default
{
	touch_start(integer total_number)
	{
		float val = 1.;
		vector vec1 = <val + val, 0, 0>;
		vector vec2 = <val + val, 0, 0>;
		llOwnerSay((string)vec1);
		llOwnerSay((string)vec2);
	}

	touch_end(integer total_number)
	{
		vector vec1 = <2., 0., 0.>;
		llOwnerSay((string)vec1);
	}
}

Options used: Constant Folding and Dead Code Removal. (In the online version of the optimizer)

Expected: both vec1 and vec2 should resolve to <2., 0., 0.>

KrsityKu avatar Jul 06 '24 15:07 KrsityKu