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 %TypeOpaque = type opaque
10 declare zeroext i1 @return_i1()
13 @globalstr = global [6 x i8] c"hello\00"
14 @globali32ptr = external global i32*
16 %struct.A = type { [8 x i8], [5 x i8] }
17 @globalstruct = external global %struct.A
19 @globalptr.align1 = external global i8, align 1
20 @globalptr.align16 = external global i8, align 16
23 define void @test(i32 addrspace(1)* dereferenceable(8) %dparam,
24 i8 addrspace(1)* dereferenceable(32) align 1 %dparam.align1,
25 i8 addrspace(1)* dereferenceable(32) align 16 %dparam.align16)
26 gc "statepoint-example" {
27 ; CHECK: The following are dereferenceable:
29 ; CHECK: %globalptr{{.*}}(aligned)
30 %globalptr = getelementptr inbounds [6 x i8], [6 x i8]* @globalstr, i32 0, i32 0
31 %load1 = load i8, i8* %globalptr
33 ; CHECK: %alloca{{.*}}(aligned)
35 %load2 = load i1, i1* %alloca
37 ; CHECK: %dparam{{.*}}(aligned)
38 %load3 = load i32, i32 addrspace(1)* %dparam
40 ; CHECK: %relocate{{.*}}(aligned)
41 %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)
42 %relocate = call i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(i32 %tok, i32 7, i32 7)
43 %load4 = load i32, i32 addrspace(1)* %relocate
46 %nparam = getelementptr i32, i32 addrspace(1)* %dparam, i32 5
47 %load5 = load i32, i32 addrspace(1)* %nparam
49 ; Load from a non-dereferenceable load
51 %nd_load = load i32*, i32** @globali32ptr
52 %load6 = load i32, i32* %nd_load
54 ; Load from a dereferenceable load
55 ; CHECK: %d4_load{{.*}}(aligned)
56 %d4_load = load i32*, i32** @globali32ptr, !dereferenceable !0
57 %load7 = load i32, i32* %d4_load
59 ; Load from an offset not covered by the dereferenceable portion
61 %d2_load = load i32*, i32** @globali32ptr, !dereferenceable !1
62 %load8 = load i32, i32* %d2_load
64 ; Load from a potentially null pointer with dereferenceable_or_null
65 ; CHECK-NOT: %d_or_null_load
66 %d_or_null_load = load i32*, i32** @globali32ptr, !dereferenceable_or_null !0
67 %load9 = load i32, i32* %d_or_null_load
69 ; Load from a non-null pointer with dereferenceable_or_null
70 ; CHECK: %d_or_null_non_null_load{{.*}}(aligned)
71 %d_or_null_non_null_load = load i32*, i32** @globali32ptr, !nonnull !2, !dereferenceable_or_null !0
72 %load10 = load i32, i32* %d_or_null_non_null_load
74 ; It's OK to overrun static array size as long as we stay within underlying object size
75 ; CHECK: %within_allocation{{.*}}(aligned)
76 %within_allocation = getelementptr inbounds %struct.A, %struct.A* @globalstruct, i64 0, i32 0, i64 10
77 %load11 = load i8, i8* %within_allocation
79 ; GEP is outside the underlying object size
80 ; CHECK-NOT: %outside_allocation
81 %outside_allocation = getelementptr inbounds %struct.A, %struct.A* @globalstruct, i64 0, i32 1, i64 10
82 %load12 = load i8, i8* %outside_allocation
84 ; Loads from aligned globals
85 ; CHECK: @globalptr.align1{{.*}}(unaligned)
86 ; CHECK: @globalptr.align16{{.*}}(aligned)
87 %load13 = load i8, i8* @globalptr.align1, align 16
88 %load14 = load i8, i8* @globalptr.align16, align 16
90 ; Loads from aligned arguments
91 ; CHECK: %dparam.align1{{.*}}(unaligned)
92 ; CHECK: %dparam.align16{{.*}}(aligned)
93 %load15 = load i8, i8 addrspace(1)* %dparam.align1, align 16
94 %load16 = load i8, i8 addrspace(1)* %dparam.align16, align 16
96 ; Loads from aligned allocas
97 ; CHECK: %alloca.align1{{.*}}(unaligned)
98 ; CHECK: %alloca.align16{{.*}}(aligned)
99 %alloca.align1 = alloca i1, align 1
100 %alloca.align16 = alloca i1, align 16
101 %load17 = load i1, i1* %alloca.align1, align 16
102 %load18 = load i1, i1* %alloca.align16, align 16
105 ; CHECK: %gep.align1.offset1{{.*}}(unaligned)
106 ; CHECK: %gep.align16.offset1{{.*}}(unaligned)
107 ; CHECK: %gep.align1.offset16{{.*}}(unaligned)
108 ; CHECK: %gep.align16.offset16{{.*}}(aligned)
109 %gep.align1.offset1 = getelementptr inbounds i8, i8 addrspace(1)* %dparam.align1, i32 1
110 %gep.align16.offset1 = getelementptr inbounds i8, i8 addrspace(1)* %dparam.align16, i32 1
111 %gep.align1.offset16 = getelementptr inbounds i8, i8 addrspace(1)* %dparam.align1, i32 16
112 %gep.align16.offset16 = getelementptr inbounds i8, i8 addrspace(1)* %dparam.align16, i32 16
113 %load19 = load i8, i8 addrspace(1)* %gep.align1.offset1, align 16
114 %load20 = load i8, i8 addrspace(1)* %gep.align16.offset1, align 16
115 %load21 = load i8, i8 addrspace(1)* %gep.align1.offset16, align 16
116 %load22 = load i8, i8 addrspace(1)* %gep.align16.offset16, align 16
118 ; CHECK-NOT: %no_deref_return
119 ; CHECK: %deref_return{{.*}}(unaligned)
120 ; CHECK: %deref_and_aligned_return{{.*}}(aligned)
121 %no_deref_return = call i32* @foo()
122 %deref_return = call dereferenceable(32) i32* @foo()
123 %deref_and_aligned_return = call dereferenceable(32) align 16 i32* @foo()
124 %load23 = load i32, i32* %no_deref_return
125 %load24 = load i32, i32* %deref_return, align 16
126 %load25 = load i32, i32* %deref_and_aligned_return, align 16
128 ; Load from a dereferenceable and aligned load
129 ; CHECK: %d4_unaligned_load{{.*}}(unaligned)
130 ; CHECK: %d4_aligned_load{{.*}}(aligned)
131 %d4_unaligned_load = load i32*, i32** @globali32ptr, !dereferenceable !0
132 %d4_aligned_load = load i32*, i32** @globali32ptr, !dereferenceable !0, !align !{i64 16}
133 %load26 = load i32, i32* %d4_unaligned_load, align 16
134 %load27 = load i32, i32* %d4_aligned_load, align 16
139 ; Just check that we don't crash.
140 ; CHECK-LABEL: 'opaque_type_crasher'
141 define void @opaque_type_crasher(%TypeOpaque* dereferenceable(16) %a) {
143 %bc = bitcast %TypeOpaque* %a to i8*
144 %ptr8 = getelementptr inbounds i8, i8* %bc, i32 8
145 %ptr32 = bitcast i8* %ptr8 to i32*
146 br i1 undef, label %if.then, label %if.end
149 %res = load i32, i32* %ptr32, align 4
156 declare i32 @llvm.experimental.gc.statepoint.p0f_i1f(i64, i32, i1 ()*, i32, i32, ...)
157 declare i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(i32, i32, i32)