• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1; RUN: opt < %s -instcombine -S | FileCheck %s
2target 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"
3
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).
7
8declare zeroext i1 @return_i1()
9declare token @llvm.experimental.gc.statepoint.p0f_i1f(i64, i32, i1 ()*, i32, i32, ...)
10declare i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(token, i32, i32)
11
12define i32 @explicit_nonnull(i32 addrspace(1)* nonnull %dparam) gc "statepoint-example" {
13; Checks that a nonnull pointer
14; CHECK-LABEL: @explicit_nonnull
15; CHECK: ret i32 1
16entry:
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) ["gc-live"(i32 addrspace(1)* %dparam)]
19    %relocate = call i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(token %tok,  i32 0, i32 0)
20    %cmp = icmp eq i32 addrspace(1)* %relocate, null
21    %ret_val = select i1 %cmp, i32 0, i32 1
22    ret i32 %ret_val
23}
24
25define i32 @implicit_nonnull(i32 addrspace(1)* %dparam) gc "statepoint-example" {
26; Checks that a nonnull pointer
27; CHECK-LABEL: @implicit_nonnull
28; CHECK: ret i32 1
29entry:
30    %cond = icmp eq i32 addrspace(1)* %dparam, null
31    br i1 %cond, label %no_gc, label %gc
32gc:
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) ["gc-live"(i32 addrspace(1)* %dparam)]
35    %relocate = call i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(token %tok,  i32 0, i32 0)
36    %cmp = icmp eq i32 addrspace(1)* %relocate, null
37    %ret_val = select i1 %cmp, i32 0, i32 1
38    ret i32 %ret_val
39no_gc:
40    unreachable
41}
42
43
44; Make sure we don't crash when processing vectors
45define <2 x i8 addrspace(1)*> @vector(<2 x i8 addrspace(1)*> %obj) gc "statepoint-example" {
46entry:
47; CHECK-LABEL: @vector
48; CHECK: gc.statepoint
49; CHECK: gc.relocate
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) ["gc-live"(<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 0, i32 0) ; (%obj, %obj)
52  ret <2 x i8 addrspace(1)*> %obj.relocated
53}
54
55define 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 0, i32 0) ; (%dparam, %dparam)
59entry:
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) ["gc-live"(i32 addrspace(1)* %dparam, i32 addrspace(1)* %dparam)]
61  %relocate = call i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(token %tok,  i32 0, i32 1)
62  ret i32 addrspace(1)* %relocate
63}
64
65
66declare void @do_safepoint()
67
68declare token @llvm.experimental.gc.statepoint.p0f_isVoidf(i64, i32, void ()*, i32, i32, ...)
69declare i8 addrspace(1)* @llvm.experimental.gc.relocate.p1i8(token, i32, i32)
70declare <2 x i8 addrspace(1)*> @llvm.experimental.gc.relocate.v2p1i8(token, i32, i32)
71