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
18 ; CHECK: movq (%rdi), [[LOADED_PTR:%[a-z]+]]
20 ; CHECK: movq %rdx, [[ARG2_SLOT:[0-9]*\(%[a-z]+\)]]
22 ; CHECK: movq [[LOADED_PTR]], [[LOADED_PTR_SLOT:[0-9]*\(%[a-z]+\)]]
23 ; Perform the indirect call.
24 ; Load the first argument
25 ; CHECK: movq [[ARG2_SLOT]], %rdi
26 ; Load the second argument
27 ; CHECK: movq [[ARG2_SLOT]], %rsi
28 ; Load the third argument
29 ; CHECK: movq [[ARG2_SLOT]], %rdx
30 ; Load the function pointer.
31 ; CHECK: movq [[LOADED_PTR_SLOT]], [[FCT_PTR:%[a-z]+]]
33 ; CHECK: callq *[[FCT_PTR]]
35 define i64 @test_bitcast(i64 (i64, i64, i64)** %arg, i1 %bool, i64 %arg2) {
37 %loaded_ptr = load i64 (i64, i64, i64)*, i64 (i64, i64, i64)** %arg, align 8
38 %raw = bitcast i64 (i64, i64, i64)* %loaded_ptr to i8*
39 switch i1 %bool, label %default [
40 i1 true, label %label_true
41 i1 false, label %label_end
50 %fct_ptr = bitcast i8* %raw to i64 (i64, i64, i64)*
51 %res = call i64 %fct_ptr(i64 %arg2, i64 %arg2, i64 %arg2)
55 ; CHECK-LABEL: @test_inttoptr
56 ; Load the value of the function pointer: %loaded_ptr
57 ; CHECK: movq (%rdi), [[LOADED_PTR:%[a-z]+]]
59 ; CHECK: movq %rdx, [[ARG2_SLOT:[0-9]*\(%[a-z]+\)]]
61 ; CHECK: movq [[LOADED_PTR]], [[LOADED_PTR_SLOT:[0-9]*\(%[a-z]+\)]]
62 ; Perform the indirect call.
63 ; Load the first argument
64 ; CHECK: movq [[ARG2_SLOT]], %rdi
65 ; Load the second argument
66 ; CHECK: movq [[ARG2_SLOT]], %rsi
67 ; Load the third argument
68 ; CHECK: movq [[ARG2_SLOT]], %rdx
69 ; Load the function pointer.
70 ; CHECK: movq [[LOADED_PTR_SLOT]], [[FCT_PTR:%[a-z]+]]
72 ; CHECK: callq *[[FCT_PTR]]
74 define i64 @test_inttoptr(i64 (i64, i64, i64)** %arg, i1 %bool, i64 %arg2) {
76 %loaded_ptr = load i64 (i64, i64, i64)*, i64 (i64, i64, i64)** %arg, align 8
77 %raw = ptrtoint i64 (i64, i64, i64)* %loaded_ptr to i64
78 switch i1 %bool, label %default [
79 i1 true, label %label_true
80 i1 false, label %label_end
89 %fct_ptr = inttoptr i64 %raw to i64 (i64, i64, i64)*
90 %res = call i64 %fct_ptr(i64 %arg2, i64 %arg2, i64 %arg2)
94 ; CHECK-LABEL: @test_ptrtoint
95 ; Load the value of the function pointer: %loaded_ptr
96 ; CHECK: movq (%rdi), [[LOADED_PTR:%[a-z]+]]
98 ; CHECK: movq %rdx, [[ARG2_SLOT:[0-9]*\(%[a-z]+\)]]
100 ; CHECK: movq [[LOADED_PTR]], [[LOADED_PTR_SLOT:[0-9]*\(%[a-z]+\)]]
101 ; Perform the indirect call.
102 ; Load the first argument
103 ; CHECK: movq [[ARG2_SLOT]], %rdi
104 ; Load the second argument
105 ; CHECK: movq [[ARG2_SLOT]], %rsi
106 ; Load the third argument
107 ; CHECK: movq [[ARG2_SLOT]], %rdx
108 ; Load the function pointer.
109 ; CHECK: movq [[LOADED_PTR_SLOT]], [[FCT_PTR:%[a-z]+]]
111 ; CHECK: callq *[[FCT_PTR]]
113 define i64 @test_ptrtoint(i64 (i64, i64, i64)** %arg, i1 %bool, i64 %arg2) {
115 %loaded_ptr = load i64 (i64, i64, i64)*, i64 (i64, i64, i64)** %arg, align 8
116 %raw = bitcast i64 (i64, i64, i64)* %loaded_ptr to i8*
117 switch i1 %bool, label %default [
118 i1 true, label %label_true
119 i1 false, label %label_end
128 %fct_int = ptrtoint i8* %raw to i64
129 %fct_ptr = inttoptr i64 %fct_int to i64 (i64, i64, i64)*
130 %res = call i64 %fct_ptr(i64 %arg2, i64 %arg2, i64 %arg2)