1 ; RUN: opt < %s -instcombine -S | FileCheck %s
2 target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128"
4 ; Uses InstCombine with DataLayout to propagate dereferenceable
5 ; attribute via gc.relocate: if the derived ptr is dereferenceable(N),
6 ; then the return attribute of gc.relocate is dereferenceable(N).
8 declare zeroext i1 @return_i1()
9 declare token @llvm.experimental.gc.statepoint.p0f_i1f(i64, i32, i1 ()*, i32, i32, ...)
10 declare i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(token, i32, i32)
12 define i32 @explicit_nonnull(i32 addrspace(1)* nonnull %dparam) gc "statepoint-example" {
13 ; Checks that a nonnull pointer
14 ; CHECK-LABEL: @explicit_nonnull
17 %load = load i32, i32 addrspace(1)* %dparam
18 %tok = tail call token (i64, i32, i1 ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_i1f(i64 0, i32 0, i1 ()* @return_i1, i32 0, i32 0, i32 0, i32 0, i32 addrspace(1)* %dparam)
19 %relocate = call i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(token %tok, i32 7, i32 7)
20 %cmp = icmp eq i32 addrspace(1)* %relocate, null
21 %ret_val = select i1 %cmp, i32 0, i32 1
25 define i32 @implicit_nonnull(i32 addrspace(1)* %dparam) gc "statepoint-example" {
26 ; Checks that a nonnull pointer
27 ; CHECK-LABEL: @implicit_nonnull
30 %cond = icmp eq i32 addrspace(1)* %dparam, null
31 br i1 %cond, label %no_gc, label %gc
33 %load = load i32, i32 addrspace(1)* %dparam
34 %tok = tail call token (i64, i32, i1 ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_i1f(i64 0, i32 0, i1 ()* @return_i1, i32 0, i32 0, i32 0, i32 0, i32 addrspace(1)* %dparam)
35 %relocate = call i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(token %tok, i32 7, i32 7)
36 %cmp = icmp eq i32 addrspace(1)* %relocate, null
37 %ret_val = select i1 %cmp, i32 0, i32 1
44 ; Make sure we don't crash when processing vectors
45 define <2 x i8 addrspace(1)*> @vector(<2 x i8 addrspace(1)*> %obj) gc "statepoint-example" {
47 ; CHECK-LABEL: @vector
48 ; CHECK: gc.statepoint
50 %safepoint_token = call token (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 0, i32 0, void ()* @do_safepoint, i32 0, i32 0, i32 0, i32 0, <2 x i8 addrspace(1)*> %obj)
51 %obj.relocated = call coldcc <2 x i8 addrspace(1)*> @llvm.experimental.gc.relocate.v2p1i8(token %safepoint_token, i32 7, i32 7) ; (%obj, %obj)
52 ret <2 x i8 addrspace(1)*> %obj.relocated
55 define i32 addrspace(1)* @canonical_base(i32 addrspace(1)* %dparam) gc "statepoint-example" {
56 ; Checks that a nonnull pointer
57 ; CHECK-LABEL: @canonical_base
58 ; CHECK: (token %tok, i32 7, i32 7) ; (%dparam, %dparam)
60 %tok = tail call token (i64, i32, i1 ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_i1f(i64 0, i32 0, i1 ()* @return_i1, i32 0, i32 0, i32 0, i32 0, i32 addrspace(1)* %dparam, i32 addrspace(1)* %dparam)
61 %relocate = call i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(token %tok, i32 7, i32 8)
62 ret i32 addrspace(1)* %relocate
66 declare void @do_safepoint()
68 declare token @llvm.experimental.gc.statepoint.p0f_isVoidf(i64, i32, void ()*, i32, i32, ...)
69 declare i8 addrspace(1)* @llvm.experimental.gc.relocate.p1i8(token, i32, i32)
70 declare <2 x i8 addrspace(1)*> @llvm.experimental.gc.relocate.v2p1i8(token, i32, i32)