Skip to content

[x86 / Refactor] Fixes to GetInt/MMRegisterBetween assignments

Summary

This merge request makes some minor corrections for safety reasons on calls to GetIntRegisterBetween and GetMMRegisterBetween, since it was mistakenly believed that AllocRegBetween (which the two functions call) allocates a register between p1 and p2 exclusive rather than p1 and p2 inclusive. As a result, the registers are now allocated for the correct number of instructions.

System

  • Processor architecture: i386, x86_64, possibly i8086 too

What is the current bug behavior?

The optimisations that use GetIntRegisterBetween and GetIntRegisterBetween, most notably "CMP/JE/CMP/@Lbl/SETE -> CMP/SETE/CMP/SETE/OR", coupled with some slightly loose prerequisites, tended to allocate a new register over more code than necessary.

What is the behavior after applying this patch?

The registers are now allocated more accurately.

Relevant logs and/or screenshots

No code outside of aoptx86 appears to get changed, although register allocations are more accurate, which may help future optimisastions. For example, in cpubase - before:

.Lj107:
	# Register ecx allocated
	movb	%dl,%cl
	cmpb	$4,%cl
	# Register r8 allocated
	seteb	%r8b
	cmpb	$11,%cl
	# Register ecx released
	seteb	%al
	# Register rflags released
	orb	%r8b,%al
	ret
	# Register r8 released
	.balign 16,0x90

After:

.Lj107:
	# Register ecx allocated
	movb	%dl,%cl
	cmpb	$4,%cl
	# Register r8 allocated
	seteb	%r8b
	cmpb	$11,%cl
	# Register ecx released
	seteb	%al
	# Register rflags released
	orb	%r8b,%al
	# Register r8 released ; <-- %r8 is now deallocated in the correct position and not after RET (which implies %r8 is needed for the return value)
	ret
	.balign 16,0x90

Merge request reports