[PATCH] D46221: [RISCV] Lower tail pseudo instruction

Mandeep Singh Grang via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed May 2 10:44:08 PDT 2018


mgrang added a comment.

Thanks for your comments @asb. I noticed that if the tail call function arguments contain a long double (which requires 16 bytes) the stack pointer does not get set correctly.

  __attribute__((noinline))
  int bar(long double a) {
    printf("### Val L: %LF\n", a);
    return a;
  }
  
  __attribute__((noinline))
  int foo() {
    return bar(1);
  }

Here's the assembly for function foo:

  Without tail call:
  _Z3foov:                                # @_Z3foov
  # %bb.0:                                # %entry
  	addi	sp, sp, -32
  	sw	ra, 28(sp)
  	lui	a0, 262128
  	sw	a0, 12(sp)
  	sw	zero, 8(sp)
  	sw	zero, 4(sp)
  	sw	zero, 0(sp)
  	mv	a0, sp
  	call	_Z3bare
  	lw	ra, 28(sp)
  	addi	sp, sp, 32
  	ret
  
  With tail call:
  _Z3foov:                                # @_Z3foov
  # %bb.0:                                # %entry
  	addi	sp, sp, -16
  	lui	a0, 262128
  	sw	a0, 12(sp)
  	sw	zero, 8(sp)
  	sw	zero, 4(sp)
  	sw	zero, 0(sp)
  	mv	a0, sp
  	addi	sp, sp, 16
  	tail	_Z3bare

The correct setting of sp with tail call should be:

  addi sp, sp, -28
  ...
  addi sp, sp, 28

I am currently trying to debug to see where this needs to be fixed. Will push the updated patch once I have the fix.


Repository:
  rL LLVM

https://reviews.llvm.org/D46221





More information about the llvm-commits mailing list