llvm.org GIT mirror llvm / release_60
Merging r326394: ------------------------------------------------------------------------ r326394 | rnk | 2018-02-28 16:09:35 -0800 (Wed, 28 Feb 2018) | 10 lines [DAE] don't remove args of musttail target/caller `musttail` requires identical signatures of caller and callee. Removing arguments breaks `musttail` semantics. PR36441 Patch by Fedor Indutny Differential Revision: https://reviews.llvm.org/D43708 ------------------------------------------------------------------------ git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_60@334464 91177308-0d34-0410-b5e6-96231b3b80d8 Tom Stellard 1 year, 3 months ago
2 changed file(s) with 53 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
506506 // MaybeLive. Initialized to a list of RetCount empty lists.
507507 RetUses MaybeLiveRetUses(RetCount);
508508
509 for (Function::const_iterator BB = F.begin(), E = F.end(); BB != E; ++BB)
510 if (const ReturnInst *RI = dyn_cast(BB->getTerminator()))
509 bool HasMustTailCalls = false;
510
511 for (Function::const_iterator BB = F.begin(), E = F.end(); BB != E; ++BB) {
512 if (const ReturnInst *RI = dyn_cast(BB->getTerminator())) {
511513 if (RI->getNumOperands() != 0 && RI->getOperand(0)->getType()
512514 != F.getFunctionType()->getReturnType()) {
513515 // We don't support old style multiple return values.
514516 MarkLive(F);
515517 return;
516518 }
519 }
520
521 // If we have any returns of `musttail` results - the signature can't
522 // change
523 if (BB->getTerminatingMustTailCall() != nullptr)
524 HasMustTailCalls = true;
525 }
526
527 if (HasMustTailCalls) {
528 DEBUG(dbgs() << "DeadArgumentEliminationPass - " << F.getName()
529 << " has musttail calls\n");
530 }
517531
518532 if (!F.hasLocalLinkage() && (!ShouldHackArguments || F.isIntrinsic())) {
519533 MarkLive(F);
525539 // Keep track of the number of live retvals, so we can skip checks once all
526540 // of them turn out to be live.
527541 unsigned NumLiveRetVals = 0;
542
543 bool HasMustTailCallers = false;
544
528545 // Loop all uses of the function.
529546 for (const Use &U : F.uses()) {
530547 // If the function is PASSED IN as an argument, its address has been
534551 MarkLive(F);
535552 return;
536553 }
554
555 // The number of arguments for `musttail` call must match the number of
556 // arguments of the caller
557 if (CS.isMustTailCall())
558 HasMustTailCallers = true;
537559
538560 // If this use is anything other than a call site, the function is alive.
539561 const Instruction *TheCall = CS.getInstruction();
579601 }
580602 }
581603
604 if (HasMustTailCallers) {
605 DEBUG(dbgs() << "DeadArgumentEliminationPass - " << F.getName()
606 << " has musttail callers\n");
607 }
608
582609 // Now we've inspected all callers, record the liveness of our return values.
583610 for (unsigned i = 0; i != RetCount; ++i)
584611 MarkValue(CreateRet(&F, i), RetValLiveness[i], MaybeLiveRetUses[i]);
592619 for (Function::const_arg_iterator AI = F.arg_begin(),
593620 E = F.arg_end(); AI != E; ++AI, ++i) {
594621 Liveness Result;
595 if (F.getFunctionType()->isVarArg()) {
622 if (F.getFunctionType()->isVarArg() || HasMustTailCallers ||
623 HasMustTailCalls) {
596624 // Variadic functions will already have a va_arg function expanded inside
597625 // them, making them potentially very sensitive to ABI changes resulting
598626 // from removing arguments entirely, so don't. For example AArch64 handles
599627 // register and stack HFAs very differently, and this is reflected in the
600628 // IR which has already been generated.
629 //
630 // `musttail` calls to this function restrict argument removal attempts.
631 // The signature of the caller must match the signature of the function.
632 //
633 // `musttail` calls in this function prevents us from changing its
634 // signature
601635 Result = Live;
602636 } else {
603637 // See what the effect of this use is (recording any uses that cause
0 ; RUN: opt -deadargelim -S < %s | FileCheck %s
1 ; PR36441
2 ; Dead arguments should not be removed in presence of `musttail` calls.
3
4 ; CHECK-LABEL: define internal void @test(i32 %a, i32 %b)
5 ; CHECK: musttail call void @foo(i32 %a, i32 0)
6 ; FIXME: we should replace those with `undef`s
7 define internal void @test(i32 %a, i32 %b) {
8 musttail call void @foo(i32 %a, i32 0)
9 ret void
10 }
11
12 ; CHECK-LABEL: define internal void @foo(i32 %a, i32 %b)
13 define internal void @foo(i32 %a, i32 %b) {
14 ret void
15 }