Skip to content

[TailCallElim] Don’t mark llvm.stackrestore with tail-call #101352

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

Merged
merged 5 commits into from
Aug 5, 2024
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
6 changes: 6 additions & 0 deletions llvm/lib/Transforms/Scalar/TailRecursionElimination.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,12 @@ static bool markTails(Function &F, OptimizationRemarkEmitter *ORE) {
isa<PseudoProbeInst>(&I))
continue;

// Bail out for intrinsic stackrestore call because it can modify
// unescaped allocas.
if (auto *II = dyn_cast<IntrinsicInst>(CI))
if (II->getIntrinsicID() == Intrinsic::stackrestore)
continue;

// Special-case operand bundles "clang.arc.attachedcall", "ptrauth", and
// "kcfi".
bool IsNoTail = CI->isNoTailCall() ||
Expand Down
14 changes: 14 additions & 0 deletions llvm/test/Transforms/TailCallElim/stackrestore.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
; RUN: opt -S -passes=tailcallelim < %s | FileCheck %s

define void @foo() {
; CHECK-LABEL: define void @foo()
; CHECK-NOT: tail call void @llvm.stackrestore.p0
;
entry:
%0 = call ptr @llvm.stacksave.p0()
call void @llvm.stackrestore.p0(ptr %0)
ret void
}

declare ptr @llvm.stacksave.p0()
declare void @llvm.stackrestore.p0(ptr)
Loading