| 1 |
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --function-signature |
| 2 |
; Use instcombine to cleanup offset computation. |
| 3 |
; Use gvn to remove duplicate computation. |
| 4 |
; RUN: opt -passes=rewrite-statepoints-for-gc,gvn,instcombine -S < %s | FileCheck %s |
| 5 |
|
| 6 |
target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128-p1:64:64" |
| 7 |
target triple = "x86_64-apple-macosx10.11.0" |
| 8 |
|
| 9 |
declare ptr addrspace(1) @llvm.experimental.gc.get.pointer.base.p1.p1(ptr addrspace(1) readnone nocapture) nounwind readnone willreturn |
| 10 |
declare i64 @llvm.experimental.gc.get.pointer.offset.p1(ptr addrspace(1) readnone nocapture) nounwind readnone willreturn |
| 11 |
|
| 12 |
declare void @foo() readonly |
| 13 |
|
| 14 |
define ptr addrspace(1) @test_simple(ptr addrspace(1) %obj1, ptr addrspace(1) %obj2, i32 %len, i1 %c) gc "statepoint-example" { |
| 15 |
; CHECK-LABEL: define {{[^@]+}}@test_simple |
| 16 |
; CHECK-SAME: (ptr addrspace(1) [[OBJ1:%.*]], ptr addrspace(1) [[OBJ2:%.*]], i32 [[LEN:%.*]], i1 [[C:%.*]]) gc "statepoint-example" { |
| 17 |
; CHECK-NEXT: entry: |
| 18 |
; CHECK-NEXT: [[OBJ1_12:%.*]] = getelementptr inbounds nuw i8, ptr addrspace(1) [[OBJ1]], i64 12 |
| 19 |
; CHECK-NEXT: [[OBJ2_16:%.*]] = getelementptr inbounds nuw i8, ptr addrspace(1) [[OBJ2]], i64 16 |
| 20 |
; CHECK-NEXT: [[OBJ_X_BASE1:%.*]] = select i1 [[C]], ptr addrspace(1) [[OBJ1]], ptr addrspace(1) [[OBJ2]], !is_base_value [[META0:![0-9]+]] |
| 21 |
; CHECK-NEXT: [[OBJ_X:%.*]] = select i1 [[C]], ptr addrspace(1) [[OBJ1_12]], ptr addrspace(1) [[OBJ2_16]] |
| 22 |
; CHECK-NEXT: [[OBJ_Y_BASE:%.*]] = select i1 [[C]], ptr addrspace(1) [[OBJ2]], ptr addrspace(1) [[OBJ1]], !is_base_value [[META0]] |
| 23 |
; CHECK-NEXT: [[OBJ_Y:%.*]] = select i1 [[C]], ptr addrspace(1) [[OBJ2_16]], ptr addrspace(1) [[OBJ1_12]] |
| 24 |
; CHECK-NEXT: [[OBJ_X_BASE1_INT:%.*]] = ptrtoint ptr addrspace(1) [[OBJ_X_BASE1]] to i64 |
| 25 |
; CHECK-NEXT: [[OBJ_X_INT:%.*]] = ptrtoint ptr addrspace(1) [[OBJ_X]] to i64 |
| 26 |
; CHECK-NEXT: [[OBJ_X_OFFSET:%.*]] = sub i64 [[OBJ_X_INT]], [[OBJ_X_BASE1_INT]] |
| 27 |
; CHECK-NEXT: [[OBJ_Y_BASE_INT:%.*]] = ptrtoint ptr addrspace(1) [[OBJ_Y_BASE]] to i64 |
| 28 |
; CHECK-NEXT: [[OBJ_Y_INT:%.*]] = ptrtoint ptr addrspace(1) [[OBJ_Y]] to i64 |
| 29 |
; CHECK-NEXT: [[OBJ_YA_OFFSET:%.*]] = sub i64 [[OBJ_Y_INT]], [[OBJ_Y_BASE_INT]] |
| 30 |
; CHECK-NEXT: [[STATEPOINT_TOKEN:%.*]] = call token (i64, i32, ptr, i32, i32, ...) @llvm.experimental.gc.statepoint.p0(i64 2882400000, i32 0, ptr nonnull elementtype(void ()) @foo, i32 0, i32 0, i32 0, i32 0) [ "deopt"(ptr addrspace(1) [[OBJ_X_BASE1]], i64 [[OBJ_X_OFFSET]], ptr addrspace(1) [[OBJ_X_BASE1]], i64 [[OBJ_X_OFFSET]], ptr addrspace(1) [[OBJ_Y_BASE]], i64 [[OBJ_YA_OFFSET]]), "gc-live"(ptr addrspace(1) [[OBJ_Y]], ptr addrspace(1) [[OBJ_Y_BASE]]) ] |
| 31 |
; CHECK-NEXT: [[OBJ_Y_RELOCATED:%.*]] = call coldcc nonnull ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token [[STATEPOINT_TOKEN]], i32 1, i32 0) |
| 32 |
; CHECK-NEXT: ret ptr addrspace(1) [[OBJ_Y_RELOCATED]] |
| 33 |
; |
| 34 |
entry: |
| 35 |
%obj1.12 = getelementptr inbounds i8, ptr addrspace(1) %obj1, i64 12 |
| 36 |
%obj2.16 = getelementptr inbounds i8, ptr addrspace(1) %obj2, i64 16 |
| 37 |
%obj.x = select i1 %c, ptr addrspace(1) %obj1.12, ptr addrspace(1) %obj2.16 |
| 38 |
%obj.y = select i1 %c, ptr addrspace(1) %obj2.16, ptr addrspace(1) %obj1.12 |
| 39 |
%obj.x.base = call ptr addrspace(1) @llvm.experimental.gc.get.pointer.base.p1.p1(ptr addrspace(1) %obj.x) |
| 40 |
%obj.x.offset = call i64 @llvm.experimental.gc.get.pointer.offset.p1(ptr addrspace(1) %obj.x) |
| 41 |
%obj.x.base2 = call ptr addrspace(1) @llvm.experimental.gc.get.pointer.base.p1.p1(ptr addrspace(1) %obj.x) |
| 42 |
%obj.x.offset2 = call i64 @llvm.experimental.gc.get.pointer.offset.p1(ptr addrspace(1) %obj.x) |
| 43 |
%obj.ya.base = call ptr addrspace(1) @llvm.experimental.gc.get.pointer.base.p1.p1(ptr addrspace(1) %obj.y) |
| 44 |
%obj.ya.offset = call i64 @llvm.experimental.gc.get.pointer.offset.p1(ptr addrspace(1) %obj.y) |
| 45 |
call void @foo() readonly [ |
| 46 |
"deopt"(ptr addrspace(1) %obj.x.base, i64 %obj.x.offset, ptr addrspace(1) %obj.x.base2, i64 %obj.x.offset2, ptr addrspace(1) %obj.ya.base, i64 %obj.ya.offset) ] |
| 47 |
ret ptr addrspace(1) %obj.y |
| 48 |
} |
| 49 |
|
| 50 |
define void @test_base_of_base(ptr addrspace(1) %obj1, ptr addrspace(1) %obj2, i32 %len, i1 %c) gc "statepoint-example" { |
| 51 |
; CHECK-LABEL: define {{[^@]+}}@test_base_of_base |
| 52 |
; CHECK-SAME: (ptr addrspace(1) [[OBJ1:%.*]], ptr addrspace(1) [[OBJ2:%.*]], i32 [[LEN:%.*]], i1 [[C:%.*]]) gc "statepoint-example" { |
| 53 |
; CHECK-NEXT: entry: |
| 54 |
; CHECK-NEXT: ret void |
| 55 |
; |
| 56 |
entry: |
| 57 |
%obj1.12 = getelementptr inbounds i8, ptr addrspace(1) %obj1, i64 12 |
| 58 |
%obj2.16 = getelementptr inbounds i8, ptr addrspace(1) %obj2, i64 16 |
| 59 |
%obj.x = select i1 %c, ptr addrspace(1) %obj1.12, ptr addrspace(1) %obj2.16 |
| 60 |
|
| 61 |
%obj.x.base = call ptr addrspace(1) @llvm.experimental.gc.get.pointer.base.p1.p1(ptr addrspace(1) %obj.x) |
| 62 |
%obj.x.base_of_base = call ptr addrspace(1) @llvm.experimental.gc.get.pointer.base.p1.p1(ptr addrspace(1) %obj.x.base) |
| 63 |
|
| 64 |
ret void |
| 65 |
} |
| 66 |
|
| 67 |
define ptr addrspace(1) @test_chained(ptr addrspace(1) %obj1, ptr addrspace(1) %obj2, i32 %len, i1 %c) gc "statepoint-example" { |
| 68 |
; CHECK-LABEL: define {{[^@]+}}@test_chained |
| 69 |
; CHECK-SAME: (ptr addrspace(1) [[OBJ1:%.*]], ptr addrspace(1) [[OBJ2:%.*]], i32 [[LEN:%.*]], i1 [[C:%.*]]) gc "statepoint-example" { |
| 70 |
; CHECK-NEXT: entry: |
| 71 |
; CHECK-NEXT: [[OBJ_X_BASE1:%.*]] = select i1 [[C]], ptr addrspace(1) [[OBJ1]], ptr addrspace(1) [[OBJ2]], !is_base_value [[META0]] |
| 72 |
; CHECK-NEXT: [[OBJ_X_BASE_GEP:%.*]] = getelementptr inbounds nuw i8, ptr addrspace(1) [[OBJ_X_BASE1]], i64 8 |
| 73 |
; CHECK-NEXT: [[OBJ_X_BASE_OF_BASE_GEP:%.*]] = getelementptr inbounds nuw i8, ptr addrspace(1) [[OBJ_X_BASE1]], i64 20 |
| 74 |
; CHECK-NEXT: [[OBJ_X_BASE_OF_BASE_OF_BASE_GEP:%.*]] = getelementptr inbounds nuw i8, ptr addrspace(1) [[OBJ_X_BASE1]], i64 24 |
| 75 |
; CHECK-NEXT: [[STATEPOINT_TOKEN:%.*]] = call token (i64, i32, ptr, i32, i32, ...) @llvm.experimental.gc.statepoint.p0(i64 2882400000, i32 0, ptr nonnull elementtype(void ()) @foo, i32 0, i32 0, i32 0, i32 0) [ "deopt"(ptr addrspace(1) [[OBJ_X_BASE1]], ptr addrspace(1) [[OBJ_X_BASE1]], ptr addrspace(1) [[OBJ_X_BASE1]], ptr addrspace(1) [[OBJ_X_BASE_GEP]], ptr addrspace(1) [[OBJ_X_BASE_OF_BASE_GEP]], ptr addrspace(1) [[OBJ_X_BASE_OF_BASE_OF_BASE_GEP]], ptr addrspace(1) [[OBJ_X_BASE1]], ptr addrspace(1) [[OBJ_X_BASE1]], ptr addrspace(1) [[OBJ_X_BASE1]], i64 0, i64 0, i64 0, i64 8, i64 20, i64 24, i64 0, i64 0, i64 0), "gc-live"(ptr addrspace(1) [[OBJ_X_BASE1]]) ] |
| 76 |
; CHECK-NEXT: [[OBJ_X_BASE1_RELOCATED:%.*]] = call coldcc ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token [[STATEPOINT_TOKEN]], i32 0, i32 0) |
| 77 |
; CHECK-NEXT: ret ptr addrspace(1) [[OBJ_X_BASE1_RELOCATED]] |
| 78 |
; |
| 79 |
entry: |
| 80 |
%obj1.12 = getelementptr inbounds i8, ptr addrspace(1) %obj1, i64 12 |
| 81 |
%obj2.16 = getelementptr inbounds i8, ptr addrspace(1) %obj2, i64 16 |
| 82 |
%obj.x = select i1 %c, ptr addrspace(1) %obj1.12, ptr addrspace(1) %obj2.16 |
| 83 |
|
| 84 |
%obj.x.base = call ptr addrspace(1) @llvm.experimental.gc.get.pointer.base.p1.p1(ptr addrspace(1) %obj.x) |
| 85 |
%obj.x.base_of_base = call ptr addrspace(1) @llvm.experimental.gc.get.pointer.base.p1.p1(ptr addrspace(1) %obj.x.base) |
| 86 |
%obj.x.base_of_base_of_base = call ptr addrspace(1) @llvm.experimental.gc.get.pointer.base.p1.p1(ptr addrspace(1) %obj.x.base_of_base) |
| 87 |
|
| 88 |
%obj.x.base_gep = getelementptr inbounds i8, ptr addrspace(1) %obj.x.base, i64 8 |
| 89 |
%obj.x.base_of_base_gep = getelementptr inbounds i8, ptr addrspace(1) %obj.x.base_of_base, i64 20 |
| 90 |
%obj.x.base_of_base_of_base_gep = getelementptr inbounds i8, ptr addrspace(1) %obj.x.base_of_base_of_base, i64 24 |
| 91 |
|
| 92 |
%obj.x.base_gep_base = call ptr addrspace(1) @llvm.experimental.gc.get.pointer.base.p1.p1(ptr addrspace(1) %obj.x.base_gep) |
| 93 |
%obj.x.base_of_base_gep_base = call ptr addrspace(1) @llvm.experimental.gc.get.pointer.base.p1.p1(ptr addrspace(1) %obj.x.base_of_base_gep) |
| 94 |
%obj.x.base_of_base_of_base_gep_base = call ptr addrspace(1) @llvm.experimental.gc.get.pointer.base.p1.p1(ptr addrspace(1) %obj.x.base_of_base_of_base_gep) |
| 95 |
|
| 96 |
%obj.x.base_offset = call i64 @llvm.experimental.gc.get.pointer.offset.p1(ptr addrspace(1) %obj.x.base) |
| 97 |
%obj.x.base_of_base_offset = call i64 @llvm.experimental.gc.get.pointer.offset.p1(ptr addrspace(1) %obj.x.base_of_base) |
| 98 |
%obj.x.base_of_base_of_base_offset = call i64 @llvm.experimental.gc.get.pointer.offset.p1(ptr addrspace(1) %obj.x.base_of_base_of_base) |
| 99 |
%obj.x.base_gep_offset = call i64 @llvm.experimental.gc.get.pointer.offset.p1(ptr addrspace(1) %obj.x.base_gep) |
| 100 |
%obj.x.base_of_base_gep_offset = call i64 @llvm.experimental.gc.get.pointer.offset.p1(ptr addrspace(1) %obj.x.base_of_base_gep) |
| 101 |
%obj.x.base_of_base_of_base_gep_offset = call i64 @llvm.experimental.gc.get.pointer.offset.p1(ptr addrspace(1) %obj.x.base_of_base_of_base_gep) |
| 102 |
%obj.x.base_gep_base_offset = call i64 @llvm.experimental.gc.get.pointer.offset.p1(ptr addrspace(1) %obj.x.base_gep_base) |
| 103 |
%obj.x.base_of_base_gep_base_offset = call i64 @llvm.experimental.gc.get.pointer.offset.p1(ptr addrspace(1) %obj.x.base_of_base_gep_base) |
| 104 |
%obj.x.base_of_base_of_base_gep_base_offset = call i64 @llvm.experimental.gc.get.pointer.offset.p1(ptr addrspace(1) %obj.x.base_of_base_of_base_gep_base) |
| 105 |
|
| 106 |
call void @foo() readonly [ |
| 107 |
"deopt"( |
| 108 |
ptr addrspace(1) %obj.x.base, |
| 109 |
ptr addrspace(1) %obj.x.base_of_base_of_base, |
| 110 |
ptr addrspace(1) %obj.x.base_of_base, |
| 111 |
ptr addrspace(1) %obj.x.base_gep, |
| 112 |
ptr addrspace(1) %obj.x.base_of_base_gep, |
| 113 |
ptr addrspace(1) %obj.x.base_of_base_of_base_gep, |
| 114 |
ptr addrspace(1) %obj.x.base_gep_base, |
| 115 |
ptr addrspace(1) %obj.x.base_of_base_gep_base, |
| 116 |
ptr addrspace(1) %obj.x.base_of_base_of_base_gep_base, |
| 117 |
i64 %obj.x.base_offset, |
| 118 |
i64 %obj.x.base_of_base_offset, |
| 119 |
i64 %obj.x.base_of_base_of_base_offset, |
| 120 |
i64 %obj.x.base_gep_offset, |
| 121 |
i64 %obj.x.base_of_base_gep_offset, |
| 122 |
i64 %obj.x.base_of_base_of_base_gep_offset, |
| 123 |
i64 %obj.x.base_gep_base_offset, |
| 124 |
i64 %obj.x.base_of_base_gep_base_offset, |
| 125 |
i64 %obj.x.base_of_base_of_base_gep_base_offset) ] |
| 126 |
|
| 127 |
ret ptr addrspace(1) %obj.x.base_of_base |
| 128 |
} |