[llvm] r366569 - [X86] for split stack, not save/restore nested arg if unused

Than McIntosh via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 19 05:54:44 PDT 2019


Author: thanm
Date: Fri Jul 19 05:54:44 2019
New Revision: 366569

URL: http://llvm.org/viewvc/llvm-project?rev=366569&view=rev
Log:
[X86] for split stack, not save/restore nested arg if unused

Summary:
For split-stack, if the nested argument (i.e. R10) is not used, no need to save/restore it in the prologue.

Reviewers: thanm

Reviewed By: thanm

Subscribers: mstorsjo, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D64673

Modified:
    llvm/trunk/lib/Target/X86/X86FrameLowering.cpp
    llvm/trunk/test/CodeGen/X86/segmented-stacks.ll

Modified: llvm/trunk/lib/Target/X86/X86FrameLowering.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86FrameLowering.cpp?rev=366569&r1=366568&r2=366569&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/X86FrameLowering.cpp (original)
+++ llvm/trunk/lib/Target/X86/X86FrameLowering.cpp Fri Jul 19 05:54:44 2019
@@ -2212,7 +2212,7 @@ HasNestArgument(const MachineFunction *M
   const Function &F = MF->getFunction();
   for (Function::const_arg_iterator I = F.arg_begin(), E = F.arg_end();
        I != E; I++) {
-    if (I->hasNestAttr())
+    if (I->hasNestAttr() && !I->use_empty())
       return true;
   }
   return false;

Modified: llvm/trunk/test/CodeGen/X86/segmented-stacks.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/segmented-stacks.ll?rev=366569&r1=366568&r2=366569&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/segmented-stacks.ll (original)
+++ llvm/trunk/test/CodeGen/X86/segmented-stacks.ll Fri Jul 19 05:54:44 2019
@@ -611,7 +611,7 @@ define void @test_nostack() #0 {
 ; X32-Linux-NOT:   calll __morestack
 
 ; X64-Linux-LABEL: test_nostack:
-; X32-Linux-NOT:   callq __morestack
+; X64-Linux-NOT:   callq __morestack
 
 ; X32ABI-LABEL: test_nostack:
 ; X32ABI-NOT:   callq __morestack
@@ -688,6 +688,45 @@ define i32 @test_sibling_call_empty_fram
 
 }
 
+; Test that unused nested argument doesn't need saving/restoring.
+
+define i32 @test_nested_unused(i32 * nest %unused) #0 {
+       %mem = alloca i32, i32 10
+       call void @dummy_use (i32* %mem, i32 10)
+       ret i32 123
+
+; X64-Linux-LABEL: test_nested_unused:
+; X64-Linux-NOT:   movq %r10, %rax
+; X64-Linux:       callq __morestack
+; X64-Linux-NOT:   movq %rax, %r10
+
+; X64-Darwin-LABEL: test_nested_unused:
+; X64-Darwin-NOT:   movq %r10, %rax
+; X64-Darwin:       callq ___morestack
+; X64-Darwin-NOT:   movq %rax, %r10
+
+; X64-FreeBSD-LABEL: test_nested_unused:
+; X64-FreeBSD-NOT:   movq %r10, %rax
+; X64-FreeBSD:       callq __morestack
+; X64-FreeBSD-NOT:   movq %rax, %r10
+
+; X64-DFlyBSD-LABEL: test_nested_unused:
+; X64-DFlyBSD-NOT:   movq %r10, %rax
+; X64-DFlyBSD:       callq __morestack
+; X64-DFlyBSD-NOT:   movq %rax, %r10
+
+; X64-MinGW-LABEL: test_nested_unused:
+; X64-MinGW-NOT:   movq %r10, %rax
+; X64-MinGW:       callq __morestack
+; X64-MinGW-NOT:   movq %rax, %r10
+
+; X32ABI-LABEL: test_nested_unused:
+; X32ABI-NOT:   movl %r10d, %eax
+; X32ABI:       callq __morestack
+; X32ABI-NOT:   movq %rax, %r10
+
+}
+
 attributes #0 = { "split-stack" }
 
 ; X64-Linux-Large: .rodata




More information about the llvm-commits mailing list