1 ; RUN: llc -mtriple x86_64-apple-darwin -O0 < %s -o - | FileCheck %s
3 ; During X86 fastisel, the address of indirect call was resolved
4 ; through bitcast, ptrtoint, and inttoptr instructions. This is valid
5 ; only if the related instructions are in that same basic block, otherwise
6 ; we may reference variables that were not live across basic blocks
7 ; resulting in undefined virtual registers.
9 ; In this example, this is illustrated by a spill/reload of the
12 ; Before this patch, the compiler was accessing two different spill
14 ; <rdar://problem/15192473>
16 ; CHECK-LABEL: @test_bitcast
17 ; Load the value of the function pointer: %loaded_ptr
19 ; CHECK: movq %rdx, [[ARG2_SLOT:[0-9]*\(%[a-z]+\)]]
20 ; CHECK: movq (%rdi), [[LOADED_PTR:%[a-z]+]]
22 ; CHECK: movq [[LOADED_PTR]], [[LOADED_PTR_SLOT:[0-9]*\(%[a-z]+\)]]
23 ; Perform the indirect call.
24 ; Load the function pointer.
25 ; CHECK: movq [[LOADED_PTR_SLOT]], [[FCT_PTR:%[a-z]+]]
26 ; Load the third argument
27 ; CHECK: movq [[ARG2_SLOT]], %rdx
28 ; Load the first argument
29 ; CHECK: movq %rdx, %rdi
30 ; Load the second argument
31 ; CHECK: movq %rdx, %rsi
33 ; CHECK: callq *[[FCT_PTR]]
35 define i64 @test_bitcast(ptr %arg, i1 %bool, i64 %arg2) {
37 %loaded_ptr = load ptr, ptr %arg, align 8
38 switch i1 %bool, label %default [
39 i1 true, label %label_true
40 i1 false, label %label_end
49 %res = call i64 %loaded_ptr(i64 %arg2, i64 %arg2, i64 %arg2)
53 ; CHECK-LABEL: @test_inttoptr
54 ; Load the value of the function pointer: %loaded_ptr
55 ; CHECK: movq %rdx, [[ARG2_SLOT:[0-9]*\(%[a-z]+\)]]
57 ; CHECK: movq (%rdi), [[LOADED_PTR:%[a-z]+]]
59 ; CHECK: movq [[LOADED_PTR]], [[LOADED_PTR_SLOT:[0-9]*\(%[a-z]+\)]]
60 ; Perform the indirect call.
61 ; Load the function pointer.
62 ; CHECK: movq [[LOADED_PTR_SLOT]], [[FCT_PTR:%[a-z]+]]
63 ; Load the third argument
64 ; CHECK: movq [[ARG2_SLOT]], %rdx
65 ; Load the first argument
66 ; CHECK: movq %rdx, %rdi
67 ; Load the second argument
68 ; CHECK: movq %rdx, %rsi
70 ; CHECK: callq *[[FCT_PTR]]
72 define i64 @test_inttoptr(ptr %arg, i1 %bool, i64 %arg2) {
74 %loaded_ptr = load ptr, ptr %arg, align 8
75 %raw = ptrtoint ptr %loaded_ptr to i64
76 switch i1 %bool, label %default [
77 i1 true, label %label_true
78 i1 false, label %label_end
87 %fct_ptr = inttoptr i64 %raw to ptr
88 %res = call i64 %fct_ptr(i64 %arg2, i64 %arg2, i64 %arg2)
92 ; CHECK-LABEL: @test_ptrtoint
94 ; CHECK: movq %rdx, [[ARG2_SLOT:[0-9]*\(%[a-z]+\)]]
95 ; Load the value of the function pointer: %loaded_ptr
96 ; CHECK: movq (%rdi), [[LOADED_PTR:%[a-z]+]]
98 ; CHECK: movq [[LOADED_PTR]], [[LOADED_PTR_SLOT:[0-9]*\(%[a-z]+\)]]
99 ; Perform the indirect call.
100 ; Load the function pointer.
101 ; CHECK: movq [[LOADED_PTR_SLOT]], [[FCT_PTR:%[a-z]+]]
102 ; Load the third argument
103 ; CHECK: movq [[ARG2_SLOT]], %rdx
104 ; Load the first argument
105 ; CHECK: movq %rdx, %rdi
106 ; Load the second argument
107 ; CHECK: movq %rdx, %rsi
109 ; CHECK: callq *[[FCT_PTR]]
111 define i64 @test_ptrtoint(ptr %arg, i1 %bool, i64 %arg2) {
113 %loaded_ptr = load ptr, ptr %arg, align 8
114 switch i1 %bool, label %default [
115 i1 true, label %label_true
116 i1 false, label %label_end
125 %fct_int = ptrtoint ptr %loaded_ptr to i64
126 %fct_ptr = inttoptr i64 %fct_int to ptr
127 %res = call i64 %fct_ptr(i64 %arg2, i64 %arg2, i64 %arg2)