summaryrefslogtreecommitdiff
path: root/test/CodeGen
diff options
context:
space:
mode:
authorQuentin Colombet <qcolombet@apple.com>2013-10-14 22:32:09 +0000
committerQuentin Colombet <qcolombet@apple.com>2013-10-14 22:32:09 +0000
commit41d6f451a50fa669fa3f71acc741de3c35f4bb40 (patch)
treea1529530f9e21708113771770791b1cb819a6ba2 /test/CodeGen
parenta6a9ac5aa1092067e6e1546226d8bdd6a4bfcf99 (diff)
downloadllvm-41d6f451a50fa669fa3f71acc741de3c35f4bb40.tar.gz
llvm-41d6f451a50fa669fa3f71acc741de3c35f4bb40.tar.bz2
llvm-41d6f451a50fa669fa3f71acc741de3c35f4bb40.tar.xz
[X86][FastISel] During X86 fastisel, the address of indirect call was resolved
through bitcast, ptrtoint, and inttoptr instructions. This is valid only if the related instructions are in that same basic block, otherwise we may reference variables that were not live accross basic blocks resulting in undefined virtual registers. The bug was exposed when both SDISel and FastISel were used within the same function, i.e., one basic block is issued with FastISel and another with SDISel, as demonstrated with the testcase. <rdar://problem/15192473> git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@192636 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/CodeGen')
-rw-r--r--test/CodeGen/X86/2013-10-14-FastISel-incorrect-vreg.ll132
1 files changed, 132 insertions, 0 deletions
diff --git a/test/CodeGen/X86/2013-10-14-FastISel-incorrect-vreg.ll b/test/CodeGen/X86/2013-10-14-FastISel-incorrect-vreg.ll
new file mode 100644
index 0000000000..3455b68fb0
--- /dev/null
+++ b/test/CodeGen/X86/2013-10-14-FastISel-incorrect-vreg.ll
@@ -0,0 +1,132 @@
+; RUN: llc -mtriple x86_64-apple-darwin -O0 < %s -o - | FileCheck %s
+;
+; During X86 fastisel, the address of indirect call was resolved
+; through bitcast, ptrtoint, and inttoptr instructions. This is valid
+; only if the related instructions are in that same basic block, otherwise
+; we may reference variables that were not live accross basic blocks
+; resulting in undefined virtual registers.
+;
+; In this example, this is illustrated by a the spill/reload of the
+; LOADED_PTR_SLOT.
+;
+; Before this patch, the compiler was accessing two different spill
+; slots.
+; <rdar://problem/15192473>
+
+; CHECK-LABEL: @test_bitcast
+; Load the value of the function pointer: %loaded_ptr
+; CHECK: movq (%rdi), [[LOADED_PTR:%[a-z]+]]
+; Spill %arg2.
+; CHECK: movq %rdx, [[ARG2_SLOT:[0-9]*\(%[a-z]+\)]]
+; Spill %loaded_ptr.
+; CHECK: movq [[LOADED_PTR]], [[LOADED_PTR_SLOT:[0-9]*\(%[a-z]+\)]]
+; Perform the indirect call.
+; Load the first argument
+; CHECK: movq [[ARG2_SLOT]], %rdi
+; Load the second argument
+; CHECK: movq [[ARG2_SLOT]], %rsi
+; Load the thrid argument
+; CHECK: movq [[ARG2_SLOT]], %rdx
+; Load the function pointer.
+; CHECK: movq [[LOADED_PTR_SLOT]], [[FCT_PTR:%[a-z]+]]
+; Call.
+; CHECK: callq *[[FCT_PTR]]
+; CHECK: ret
+define i64 @test_bitcast(i64 (i64, i64, i64)** %arg, i1 %bool, i64 %arg2) {
+entry:
+ %loaded_ptr = load i64 (i64, i64, i64)** %arg, align 8
+ %raw = bitcast i64 (i64, i64, i64)* %loaded_ptr to i8*
+ switch i1 %bool, label %default [
+ i1 true, label %label_true
+ i1 false, label %label_end
+ ]
+default:
+ unreachable
+
+label_true:
+ br label %label_end
+
+label_end:
+ %fct_ptr = bitcast i8* %raw to i64 (i64, i64, i64)*
+ %res = call i64 %fct_ptr(i64 %arg2, i64 %arg2, i64 %arg2)
+ ret i64 %res
+}
+
+; CHECK-LABEL: @test_inttoptr
+; Load the value of the function pointer: %loaded_ptr
+; CHECK: movq (%rdi), [[LOADED_PTR:%[a-z]+]]
+; Spill %arg2.
+; CHECK: movq %rdx, [[ARG2_SLOT:[0-9]*\(%[a-z]+\)]]
+; Spill %loaded_ptr.
+; CHECK: movq [[LOADED_PTR]], [[LOADED_PTR_SLOT:[0-9]*\(%[a-z]+\)]]
+; Perform the indirect call.
+; Load the first argument
+; CHECK: movq [[ARG2_SLOT]], %rdi
+; Load the second argument
+; CHECK: movq [[ARG2_SLOT]], %rsi
+; Load the thrid argument
+; CHECK: movq [[ARG2_SLOT]], %rdx
+; Load the function pointer.
+; CHECK: movq [[LOADED_PTR_SLOT]], [[FCT_PTR:%[a-z]+]]
+; Call.
+; CHECK: callq *[[FCT_PTR]]
+; CHECK: ret
+define i64 @test_inttoptr(i64 (i64, i64, i64)** %arg, i1 %bool, i64 %arg2) {
+entry:
+ %loaded_ptr = load i64 (i64, i64, i64)** %arg, align 8
+ %raw = ptrtoint i64 (i64, i64, i64)* %loaded_ptr to i64
+ switch i1 %bool, label %default [
+ i1 true, label %label_true
+ i1 false, label %label_end
+ ]
+default:
+ unreachable
+
+label_true:
+ br label %label_end
+
+label_end:
+ %fct_ptr = inttoptr i64 %raw to i64 (i64, i64, i64)*
+ %res = call i64 %fct_ptr(i64 %arg2, i64 %arg2, i64 %arg2)
+ ret i64 %res
+}
+
+; CHECK-LABEL: @test_ptrtoint
+; Load the value of the function pointer: %loaded_ptr
+; CHECK: movq (%rdi), [[LOADED_PTR:%[a-z]+]]
+; Spill %arg2.
+; CHECK: movq %rdx, [[ARG2_SLOT:[0-9]*\(%[a-z]+\)]]
+; Spill %loaded_ptr.
+; CHECK: movq [[LOADED_PTR]], [[LOADED_PTR_SLOT:[0-9]*\(%[a-z]+\)]]
+; Perform the indirect call.
+; Load the first argument
+; CHECK: movq [[ARG2_SLOT]], %rdi
+; Load the second argument
+; CHECK: movq [[ARG2_SLOT]], %rsi
+; Load the thrid argument
+; CHECK: movq [[ARG2_SLOT]], %rdx
+; Load the function pointer.
+; CHECK: movq [[LOADED_PTR_SLOT]], [[FCT_PTR:%[a-z]+]]
+; Call.
+; CHECK: callq *[[FCT_PTR]]
+; CHECK: ret
+define i64 @test_ptrtoint(i64 (i64, i64, i64)** %arg, i1 %bool, i64 %arg2) {
+entry:
+ %loaded_ptr = load i64 (i64, i64, i64)** %arg, align 8
+ %raw = bitcast i64 (i64, i64, i64)* %loaded_ptr to i8*
+ switch i1 %bool, label %default [
+ i1 true, label %label_true
+ i1 false, label %label_end
+ ]
+default:
+ unreachable
+
+label_true:
+ br label %label_end
+
+label_end:
+ %fct_int = ptrtoint i8* %raw to i64
+ %fct_ptr = inttoptr i64 %fct_int to i64 (i64, i64, i64)*
+ %res = call i64 %fct_ptr(i64 %arg2, i64 %arg2, i64 %arg2)
+ ret i64 %res
+}