1 ; RUN: opt -print-memderefs -analyze -S <%s | FileCheck %s
3 ; Uses the print-deref (+ analyze to print) pass to run
4 ; isDereferenceablePointer() on many load instruction operands
6 target datalayout = "e"
8 declare zeroext i1 @return_i1()
10 @globalstr = global [6 x i8] c"hello\00"
11 @globali32ptr = external global i32*
13 define void @test(i32 addrspace(1)* dereferenceable(8) %dparam) gc "statepoint-example" {
14 ; CHECK: The following are dereferenceable:
23 ; CHECK-NOT: %d_or_null_load
24 ; CHECK: %d_or_null_non_null_load
26 %globalptr = getelementptr inbounds [6 x i8], [6 x i8]* @globalstr, i32 0, i32 0
27 %load1 = load i8, i8* %globalptr
29 %load2 = load i1, i1* %alloca
30 %load3 = load i32, i32 addrspace(1)* %dparam
31 %tok = tail call i32 (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)
32 %relocate = call i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(i32 %tok, i32 7, i32 7)
33 %load4 = load i32, i32 addrspace(1)* %relocate
34 %nparam = getelementptr i32, i32 addrspace(1)* %dparam, i32 5
35 %load5 = load i32, i32 addrspace(1)* %nparam
37 ; Load from a non-dereferenceable load
38 %nd_load = load i32*, i32** @globali32ptr
39 %load6 = load i32, i32* %nd_load
41 ; Load from a dereferenceable load
42 %d4_load = load i32*, i32** @globali32ptr, !dereferenceable !0
43 %load7 = load i32, i32* %d4_load
45 ; Load from an offset not covered by the dereferenceable portion
46 %d2_load = load i32*, i32** @globali32ptr, !dereferenceable !1
47 %load8 = load i32, i32* %d2_load
49 ; Load from a potentially null pointer with dereferenceable_or_null
50 %d_or_null_load = load i32*, i32** @globali32ptr, !dereferenceable_or_null !0
51 %load9 = load i32, i32* %d_or_null_load
53 ; Load from a non-null pointer with dereferenceable_or_null
54 %d_or_null_non_null_load = load i32*, i32** @globali32ptr, !nonnull !2, !dereferenceable_or_null !0
55 %load10 = load i32, i32* %d_or_null_non_null_load
60 declare i32 @llvm.experimental.gc.statepoint.p0f_i1f(i64, i32, i1 ()*, i32, i32, ...)
61 declare i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(i32, i32, i32)