Skip to content
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

Don't enforce the frame pointer for functions with GCC-style inline asm #3685

Merged
merged 1 commit into from
Apr 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions dmd/declaration.h
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,7 @@ class FuncDeclaration : public Declaration
// 4 if there's an assert(0)
// 8 if there's inline asm
// 16 if there are multiple return statements
// IN_LLVM: 32 if there's DMD-style inline asm
int hasReturnExp;

// Support for NRVO (named return value optimization)
Expand Down
5 changes: 4 additions & 1 deletion gen/asmstmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ Statement *asmSemantic(AsmStatement *s, Scope *sc) {
return gccAsmSemantic(gas, sc);
}

// this is DMD-style asm
sc->func->hasReturnExp |= 32;

auto ias = createInlineAsmStatement(s->loc, s->tokens);
s = ias;

Expand Down Expand Up @@ -156,7 +159,7 @@ void AsmStatement_toIR(InlineAsmStatement *stmt, IRState *irs) {
LOG_SCOPE;

// sanity check
assert(irs->func()->decl->hasReturnExp & 8);
assert((irs->func()->decl->hasReturnExp & 40) == 40);

// get asm block
IRAsmBlock *asmblock = irs->asmBlock;
Expand Down
4 changes: 2 additions & 2 deletions gen/functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1232,8 +1232,8 @@ void DtoDefineFunction(FuncDeclaration *fd, bool linkageAvailableExternally) {
emitDMDStyleFunctionTrace(*gIR, fd, funcGen);
}

// disable frame-pointer-elimination for functions with inline asm
if (fd->hasReturnExp & 8) // has inline asm
// disable frame-pointer-elimination for functions with DMD-style inline asm
if (fd->hasReturnExp & 32)
{
#if LDC_LLVM_VER >= 800
func->addFnAttr(
Expand Down
21 changes: 21 additions & 0 deletions tests/codegen/asm_gcc_no_fp.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Makes sure the frame pointer isn't enforced for GCC-style asm.

// REQUIRES: target_X86

// RUN: %ldc -mtriple=x86_64-linux-gnu -mattr=avx -O -output-s -of=%t.s %s
// RUN: FileCheck %s < %t.s

alias byte32 = __vector(byte[32]);

// CHECK: _D13asm_gcc_no_fp3xorFNhG32gQgZQj:
byte32 xor(byte32 a, byte32 b)
{
// CHECK-NEXT: .cfi_startproc
byte32 r;
// CHECK-NEXT: #APP
// CHECK-NEXT: vxorps %ymm0, %ymm1, %ymm0
// CHECK-NEXT: #NO_APP
asm { "vxorps %0, %1, %2" : "=v" (r) : "v" (a), "v" (b); }
// CHECK-NEXT: retq
return r;
}