Skip to content

Commit d77f07d

Browse files
authored
[TailCallElim] Don’t mark llvm.stackrestore with tail-call (llvm#101352)
This is to teach tailcallelim transformation not to mark llvm.stackrestore with tail-call, as the intrinsic call can modify unescaped allocas from the caller.   This fixes a problem found with our downstream testing. The problem can also be shown when running the test case llvm/test/Transforms/MemCpyOpt/stackrestore with passes=”tailcallelim, memcpyopt”.
1 parent 2578315 commit d77f07d

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

llvm/lib/Transforms/Scalar/TailRecursionElimination.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,12 @@ static bool markTails(Function &F, OptimizationRemarkEmitter *ORE) {
243243
isa<PseudoProbeInst>(&I))
244244
continue;
245245

246+
// Bail out for intrinsic stackrestore call because it can modify
247+
// unescaped allocas.
248+
if (auto *II = dyn_cast<IntrinsicInst>(CI))
249+
if (II->getIntrinsicID() == Intrinsic::stackrestore)
250+
continue;
251+
246252
// Special-case operand bundles "clang.arc.attachedcall", "ptrauth", and
247253
// "kcfi".
248254
bool IsNoTail = CI->isNoTailCall() ||
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
; RUN: opt -S -passes=tailcallelim < %s | FileCheck %s
2+
3+
define void @foo() {
4+
; CHECK-LABEL: define void @foo()
5+
; CHECK-NOT: tail call void @llvm.stackrestore.p0
6+
;
7+
entry:
8+
%0 = call ptr @llvm.stacksave.p0()
9+
call void @llvm.stackrestore.p0(ptr %0)
10+
ret void
11+
}
12+
13+
declare ptr @llvm.stacksave.p0()
14+
declare void @llvm.stackrestore.p0(ptr)

0 commit comments

Comments
 (0)