Skip to content

Commit 3d9841a

Browse files
authoredJul 18, 2018
Merge pull request #41 from schweitzpgi/release_60
Release 60 -merge lastest changes from LLVM
2 parents f26a3ec + eab3b4c commit 3d9841a

File tree

2 files changed

+53
-3
lines changed

2 files changed

+53
-3
lines changed
 

‎lib/Transforms/IPO/DeadArgumentElimination.cpp

+37-3
Original file line numberDiff line numberDiff line change
@@ -507,14 +507,28 @@ void DeadArgumentEliminationPass::SurveyFunction(const Function &F) {
507507
// MaybeLive. Initialized to a list of RetCount empty lists.
508508
RetUses MaybeLiveRetUses(RetCount);
509509

510-
for (Function::const_iterator BB = F.begin(), E = F.end(); BB != E; ++BB)
511-
if (const ReturnInst *RI = dyn_cast<ReturnInst>(BB->getTerminator()))
510+
bool HasMustTailCalls = false;
511+
512+
for (Function::const_iterator BB = F.begin(), E = F.end(); BB != E; ++BB) {
513+
if (const ReturnInst *RI = dyn_cast<ReturnInst>(BB->getTerminator())) {
512514
if (RI->getNumOperands() != 0 && RI->getOperand(0)->getType()
513515
!= F.getFunctionType()->getReturnType()) {
514516
// We don't support old style multiple return values.
515517
MarkLive(F);
516518
return;
517519
}
520+
}
521+
522+
// If we have any returns of `musttail` results - the signature can't
523+
// change
524+
if (BB->getTerminatingMustTailCall() != nullptr)
525+
HasMustTailCalls = true;
526+
}
527+
528+
if (HasMustTailCalls) {
529+
DEBUG(dbgs() << "DeadArgumentEliminationPass - " << F.getName()
530+
<< " has musttail calls\n");
531+
}
518532

519533
if (!F.hasLocalLinkage() && (!ShouldHackArguments || F.isIntrinsic())) {
520534
MarkLive(F);
@@ -526,6 +540,9 @@ void DeadArgumentEliminationPass::SurveyFunction(const Function &F) {
526540
// Keep track of the number of live retvals, so we can skip checks once all
527541
// of them turn out to be live.
528542
unsigned NumLiveRetVals = 0;
543+
544+
bool HasMustTailCallers = false;
545+
529546
// Loop all uses of the function.
530547
for (const Use &U : F.uses()) {
531548
// If the function is PASSED IN as an argument, its address has been
@@ -536,6 +553,11 @@ void DeadArgumentEliminationPass::SurveyFunction(const Function &F) {
536553
return;
537554
}
538555

556+
// The number of arguments for `musttail` call must match the number of
557+
// arguments of the caller
558+
if (CS.isMustTailCall())
559+
HasMustTailCallers = true;
560+
539561
// If this use is anything other than a call site, the function is alive.
540562
const Instruction *TheCall = CS.getInstruction();
541563
if (!TheCall) { // Not a direct call site?
@@ -580,6 +602,11 @@ void DeadArgumentEliminationPass::SurveyFunction(const Function &F) {
580602
}
581603
}
582604

605+
if (HasMustTailCallers) {
606+
DEBUG(dbgs() << "DeadArgumentEliminationPass - " << F.getName()
607+
<< " has musttail callers\n");
608+
}
609+
583610
// Now we've inspected all callers, record the liveness of our return values.
584611
for (unsigned i = 0; i != RetCount; ++i)
585612
MarkValue(CreateRet(&F, i), RetValLiveness[i], MaybeLiveRetUses[i]);
@@ -593,12 +620,19 @@ void DeadArgumentEliminationPass::SurveyFunction(const Function &F) {
593620
for (Function::const_arg_iterator AI = F.arg_begin(),
594621
E = F.arg_end(); AI != E; ++AI, ++i) {
595622
Liveness Result;
596-
if (F.getFunctionType()->isVarArg()) {
623+
if (F.getFunctionType()->isVarArg() || HasMustTailCallers ||
624+
HasMustTailCalls) {
597625
// Variadic functions will already have a va_arg function expanded inside
598626
// them, making them potentially very sensitive to ABI changes resulting
599627
// from removing arguments entirely, so don't. For example AArch64 handles
600628
// register and stack HFAs very differently, and this is reflected in the
601629
// IR which has already been generated.
630+
//
631+
// `musttail` calls to this function restrict argument removal attempts.
632+
// The signature of the caller must match the signature of the function.
633+
//
634+
// `musttail` calls in this function prevents us from changing its
635+
// signature
602636
Result = Live;
603637
} else {
604638
// See what the effect of this use is (recording any uses that cause
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
; RUN: opt -deadargelim -S < %s | FileCheck %s
2+
; PR36441
3+
; Dead arguments should not be removed in presence of `musttail` calls.
4+
5+
; CHECK-LABEL: define internal void @test(i32 %a, i32 %b)
6+
; CHECK: musttail call void @foo(i32 %a, i32 0)
7+
; FIXME: we should replace those with `undef`s
8+
define internal void @test(i32 %a, i32 %b) {
9+
musttail call void @foo(i32 %a, i32 0)
10+
ret void
11+
}
12+
13+
; CHECK-LABEL: define internal void @foo(i32 %a, i32 %b)
14+
define internal void @foo(i32 %a, i32 %b) {
15+
ret void
16+
}

0 commit comments

Comments
 (0)
Please sign in to comment.