Skip to content

[i386 / Fixes 3.2 Only] Corrections to IMUL -> LEA/LEA optimisations

Note that this request is for the fixes_3_2 branch only; it is not applicable to the trunk.

Summary

This merge request fixes the issue raised in #39955 (closed) where some scalar multiplications by 6 or 12 under the 386 processor would be optimised incorrectly.

System

  • Processor architecture: i386

What is the current bug behavior?

In some situations, especially during certain array accesses, multiplications by 6 or 12 are incorrectly optimised to become multiplications by 10 and 36 respectively. This is because when the peephole optimizer attempts to convert an imul $6,%reg1,%reg2 or imul $12,%reg1,%reg2 instruction, it doesn't properly account for the situation where %reg1 and %reg2 are the same register.

What is the behavior after applying this patch?

Such multiplications are correctly optimised. See #39955 (closed) for the test project.

Relevant logs and/or screenshots

In the test project on #39955 (closed) with an array size of 5 (creates a multiplication by 6) - before:

# [18] S := @Str[I];
	...
	leal	(%eax,%eax,1),%eax
	leal	(%eax,%eax,4),%eax

After:

# [18] S := @Str[I];
	...
	leal	(%eax,%eax,2),%eax
	addl	%eax,%eax

Additional notes

It initially appeared that multiplications by 10 suffered from a similar problem, but the code in that case branch is different enough that it actually works properly and no change is needed there, since the second instruction will always be an ADD instruction whether or not %reg1 and %reg2 are equal.

Edited by J. Gareth "Kit" Moreton

Merge request reports