jasmin icon indicating copy to clipboard operation
jasmin copied to clipboard

Useless RSP mov

Open eponier opened this issue 2 years ago • 1 comments

#[returnaddress=stack]
fn id (reg u64 x) -> reg u64 {
  return x;
}

export fn main () -> reg u64 {
  reg u64 res;
  stack u64 s;
  s = 0;
  res = s;
  res = id(res);
  return res;
}

gives the following asm with a useless assignment

	.att_syntax
	.text
	.p2align	5
	.globl	_main
	.globl	main
_main:
main:
	movq	%rsp, %r10
	leaq	-8(%rsp), %rsp
	andq	$-8, %rsp
	movq	$0, (%rsp)
	movq	(%rsp), %rax
	leaq	-8(%rsp), %rsp
	leaq	Lmain$1(%rip), %rcx
	movq	%rcx, (%rsp)
	jmp 	Lid$1
Lmain$1:
	leaq	8(%rsp), %rsp  // <- seems useless
	movq	%r10, %rsp
	ret 
Lid$1:
	jmp 	*(%rsp)

eponier avatar Mar 15 '22 16:03 eponier

There is a similar issue when doing several calls in sequence: stack memory is freed (RSP increases) and allocated again just after (RSP decreases).

vbgl avatar Mar 15 '22 16:03 vbgl