Skip to content

Sibcall optimization rejects sret-using functions #8605

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
llvmbot opened this issue Sep 26, 2010 · 3 comments
Open

Sibcall optimization rejects sret-using functions #8605

llvmbot opened this issue Sep 26, 2010 · 3 comments
Labels
backend:X86 bugzilla Issues migrated from bugzilla confirmed Verified by a second party

Comments

@llvmbot
Copy link
Member

llvmbot commented Sep 26, 2010

Bugzilla Link 8233
Version trunk
OS All
Reporter LLVM Bugzilla Contributor
CC @topperc,@RKSimon,@Kojoley,@rotateright

Extended Description

Sibcall optimization does not take place when 'sret' is used on X86-64. For example:

$ cat test.ll
; ModuleID = '/home/urxae/.ccache/test.tmp.s010625.15525.ii'
target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
target triple = "x86_64-unknown-linux-gnu"

%struct.Foo = type { [3 x i64] }

define void @_Z10tailcallerv(%struct.Foo* sret %agg.result) nounwind {
entry:
  tail call void @_Z10tailcalleev(%struct.Foo* sret %agg.result) nounwind
  ret void
}

declare void @_Z10tailcalleev(%struct.Foo* sret) nounwind
$ llc test.ll -o -
	.file	"test.ll"
	.text
	.globl	_Z10tailcallerv
	.align	16, 0x90
	.type	_Z10tailcallerv,@function
_Z10tailcallerv:                        # @_Z10tailcallerv
# BB#0:                                 # %entry
	pushq	%rbx
	movq	%rdi, %rbx
	callq	_Z10tailcalleev
	movq	%rbx, %rax
	popq	%rbx
	ret
.Ltmp0:
	.size	_Z10tailcallerv, .Ltmp0-_Z10tailcallerv


	.section	.note.GNU-stack,"",@progbits

This despite the fact that the code for tailcaller() here only needs to be a jump to tailcallee()...

Removing sret from tailcaller() doesn't help, but removing it from both works.
(Note: removing it only from tailcallee() shouldn't work, because then tailcaller() can't copy %rdi to %rax on exit)

32-bit x86 code seems to have this problem as well, by the way.

@llvmbot
Copy link
Member Author

llvmbot commented Jan 15, 2013

rdar://13017006

@Kojoley
Copy link
Contributor

Kojoley commented May 11, 2020

Strangely, ARM64 is not affected, but ARM (32bit) does.

Some abandoned tries to fix the issue:
https://reviews.llvm.org/D45653
https://reviews.llvm.org/D46262

A simple C++ reproducer that is optimized by ICC (an not by Clang or GCC):

struct X { ~X() {} };

X bar();
X foo() {
return bar();
}

https://godbolt.org/z/_zW_bG

@Kojoley
Copy link
Contributor

Kojoley commented May 11, 2020

*** Bug llvm/llvm-bugzilla-archive#28417 has been marked as a duplicate of this bug. ***

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 3, 2021
@llvmbot llvmbot added the confirmed Verified by a second party label Jan 26, 2022
chelcassanova pushed a commit to chelcassanova/llvm-project that referenced this issue Apr 26, 2024
[lldb] Support reconstructing types compiled with a different abi name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend:X86 bugzilla Issues migrated from bugzilla confirmed Verified by a second party
Projects
None yet
Development

No branches or pull requests

3 participants