Skip to content

[x86-64 / Bug Fix] RIP-relative references were made absolute in minmax optimisations by mistake (Fixes #40732)

J. Gareth "Kit" Moreton requested to merge CuriousKit/optimisations:i40732 into main

Summary

This merge request fixes the bug raised in #40732 (closed) where absolute references were inserted into the instruction stream instead of RIP-relative ones.

This merge request fixes #40732 (closed).

System

  • Operating system: Windows, Darwin (anything that uses RIP)
  • Processor architecture: x86_64

What is the current bug behavior?

In some situations, code that optimises into a minmax-based inline node will produce instructions that contain absolute references to symbols instead of relative ones.

What is the behavior after applying this patch?

References should now always be relative.

Relevant logs and/or screenshots

The test supplied in #40732 (closed) showcases the problematic code - before:

	...
# [14] if gPenWidth<=0 then
	xorl	%eax,%eax
	cmpl	$0,TC_$P$I40732_$$_GPENWIDTH
	cmovgl	TC_$P$I40732_$$_GPENWIDTH,%eax
	movl	%eax,TC_$P$I40732_$$_GPENWIDTH(%rip)
	...

After:

	...
# [14] if gPenWidth<=0 then
	xorl	%eax,%eax
	cmpl	$0,TC_$P$I40732_$$_GPENWIDTH(%rip)
	cmovgl	TC_$P$I40732_$$_GPENWIDTH(%rip),%eax
	movl	%eax,TC_$P$I40732_$$_GPENWIDTH(%rip)
	...

Additional Notes

The error was caused by using taicpu.op_ref_reg etc. instead of emit_op_ref_reg; the latter transforms referenes to use RIP if required, whereas the former does not.

Edited by J. Gareth "Kit" Moreton

Merge request reports