|
| 1 | +; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py |
| 2 | +; RUN: llc < %s -mtriple=x86_64-unknown-unknown -x86-asm-syntax=intel | FileCheck %s |
| 3 | +; ; RUN: llc < %s -mtriple=i686-unknown-unknown | FileCheck %s |
| 4 | + |
| 5 | +; Test correct handling of a musttail call with a byval struct argument. |
| 6 | + |
| 7 | +%struct.1xi32 = type { [1 x i32] } |
| 8 | +%struct.3xi32 = type { [3 x i32] } |
| 9 | +%struct.5xi32 = type { [5 x i32] } |
| 10 | + |
| 11 | +declare dso_local i32 @Func1(ptr byval(%struct.1xi32) %0) |
| 12 | +declare dso_local i32 @Func3(ptr byval(%struct.3xi32) %0) |
| 13 | +declare dso_local i32 @Func5(ptr byval(%struct.5xi32) %0) |
| 14 | +declare dso_local i32 @FuncManyArgs(i32 %0, i32 %1, i32 %2, i32 %3, i32 %4, i32 %5, i8 %6, ptr byval(%struct.5xi32) %7) |
| 15 | + |
| 16 | +define dso_local i32 @test1(ptr byval(%struct.1xi32) %0) { |
| 17 | +; CHECK-LABEL: test1: |
| 18 | +; CHECK: # %bb.0: |
| 19 | +; CHECK-NEXT: jmp Func1 # TAILCALL |
| 20 | + %r = musttail call i32 @Func1(ptr byval(%struct.1xi32) %0) |
| 21 | + ret i32 %r |
| 22 | +} |
| 23 | + |
| 24 | +define dso_local i32 @test3(ptr byval(%struct.3xi32) %0) { |
| 25 | +; CHECK-LABEL: test3: |
| 26 | +; CHECK: # %bb.0: |
| 27 | +; CHECK-NEXT: jmp Func3 # TAILCALL |
| 28 | + %r = musttail call i32 @Func3(ptr byval(%struct.3xi32) %0) |
| 29 | + ret i32 %r |
| 30 | +} |
| 31 | + |
| 32 | +; sizeof(%struct.5xi32) > 16, in x64 this is passed on stack. |
| 33 | +define dso_local i32 @test5(ptr byval(%struct.5xi32) %0) { |
| 34 | +; CHECK-LABEL: test5: |
| 35 | +; CHECK: # %bb.0: |
| 36 | +; CHECK-NEXT: jmp Func5 # TAILCALL |
| 37 | + %r = musttail call i32 @Func5(ptr byval(%struct.5xi32) %0) |
| 38 | + ret i32 %r |
| 39 | +} |
| 40 | + |
| 41 | +; Test passing multiple arguments with different sizes on stack. In x64 Linux |
| 42 | +; the first 6 are passed by register. |
| 43 | +define dso_local i32 @testManyArgs(i32 %0, i32 %1, i32 %2, i32 %3, i32 %4, i32 %5, i8 %6, ptr byval(%struct.5xi32) %7) { |
| 44 | +; CHECK-LABEL: testManyArgs: |
| 45 | +; CHECK: # %bb.0: |
| 46 | +; CHECK-NEXT: jmp FuncManyArgs # TAILCALL |
| 47 | + %r = musttail call i32 @FuncManyArgs(i32 %0, i32 %1, i32 %2, i32 %3, i32 %4, i32 %5, i8 %6, ptr byval(%struct.5xi32) %7) |
| 48 | + ret i32 %r |
| 49 | +} |
| 50 | + |
| 51 | +define dso_local i32 @testRecursion(i32 %0, i32 %1, i32 %2, i32 %3, i32 %4, i32 %5, i8 %6, ptr byval(%struct.5xi32) %7) { |
| 52 | +; CHECK-LABEL: testRecursion: |
| 53 | +; CHECK: # %bb.0: |
| 54 | +; CHECK-NEXT: jmp testRecursion # TAILCALL |
| 55 | + %r = musttail call i32 @testRecursion(i32 %0, i32 %1, i32 %2, i32 %3, i32 %4, i32 %5, i8 %6, ptr byval(%struct.5xi32) %7) |
| 56 | + ret i32 %r |
| 57 | +} |
| 58 | + |
| 59 | +define dso_local i32 @swap(ptr byval(%struct.1xi32) %0, ptr byval(%struct.1xi32) %1) noinline { |
| 60 | +; CHECK-LABEL: swap: |
| 61 | +; CHECK: # %bb.0: # %entry |
| 62 | +; CHECK-NEXT: mov eax, dword ptr [rsp + 8] |
| 63 | +; CHECK-NEXT: add eax, dword ptr [rsp + 16] |
| 64 | +; CHECK-NEXT: ret |
| 65 | +entry: |
| 66 | + %a.ptr = getelementptr inbounds %struct.1xi32, ptr %0, i32 0, i32 0, i32 0 |
| 67 | + %a = load i32, ptr %a.ptr, align 4 |
| 68 | + %b.ptr = getelementptr inbounds %struct.1xi32, ptr %1, i32 0, i32 0, i32 0 |
| 69 | + %b = load i32, ptr %b.ptr, align 4 |
| 70 | + %sum = add i32 %a, %b |
| 71 | + ret i32 %sum |
| 72 | +} |
| 73 | + |
| 74 | +define dso_local i32 @swapByValArguments(ptr byval(%struct.1xi32) %0, ptr byval(%struct.1xi32) %1) { |
| 75 | +; CHECK-LABEL: swapArguments: |
| 76 | +; CHECK: # %bb.0: |
| 77 | + |
| 78 | +; CHECK-NEXT: mov eax, dword ptr [rsp + 8] |
| 79 | +; CHECK-NEXT: mov dword ptr [rsp - 16], eax |
| 80 | +; CHECK-NEXT: mov ecx, dword ptr [rsp + 16] |
| 81 | +; CHECK-NEXT: mov dword ptr [rsp - 8], ecx |
| 82 | + |
| 83 | +; CHECK-NEXT: mov dword ptr [rsp + 8], ecx |
| 84 | +; CHECK-NEXT: mov dword ptr [rsp + 16], eax |
| 85 | +; CHECK-NEXT: jmp swap # TAILCALL |
| 86 | + %r = musttail call i32 @swap(ptr byval(%struct.1xi32) %1, ptr byval(%struct.1xi32) %0) |
| 87 | + ret i32 %r |
| 88 | +} |
0 commit comments