1 ; RUN: opt < %s -basic-aa -aa-eval -print-all-alias-modref-info -disable-output 2>&1 | FileCheck %s
4 ; CHECK: NoAlias: i32* %gep1, i32* %gep2
5 define void @t1([8 x i32]* %p, i32 %addend, i32* %q) {
6 %knownnonzero = load i32, i32* %q, !range !0
7 %add = add nsw nuw i32 %addend, %knownnonzero
8 %gep1 = getelementptr [8 x i32], [8 x i32]* %p, i32 2, i32 %addend
9 %gep2 = getelementptr [8 x i32], [8 x i32]* %p, i32 2, i32 %add
14 ; CHECK: MayAlias: i32* %gep1, i32* %gep2
15 define void @t2([8 x i32]* %p, i32 %addend, i32* %q) {
16 %knownnonzero = load i32, i32* %q, !range !0
17 %add = add nsw nuw i32 %addend, %knownnonzero
18 %gep1 = getelementptr [8 x i32], [8 x i32]* %p, i32 1, i32 %addend
19 %gep2 = getelementptr [8 x i32], [8 x i32]* %p, i32 0, i32 %add
24 ; CHECK: MustAlias: i32* %gep1, i32* %gep2
25 define void @t3([8 x i32]* %p, i32 %addend, i32* %q) {
26 %knownnonzero = load i32, i32* %q, !range !0
27 %add = add nsw nuw i32 %addend, %knownnonzero
28 %gep1 = getelementptr [8 x i32], [8 x i32]* %p, i32 0, i32 %add
29 %gep2 = getelementptr [8 x i32], [8 x i32]* %p, i32 0, i32 %add
34 ; CHECK: MayAlias: i32* %gep1, i32* %gep2
35 define void @t4([8 x i32]* %p, i32 %addend, i32* %q) {
36 %knownnonzero = load i32, i32* %q, !range !0
37 %add = add nsw nuw i32 %addend, %knownnonzero
38 %gep1 = getelementptr [8 x i32], [8 x i32]* %p, i32 1, i32 %addend
39 %gep2 = getelementptr [8 x i32], [8 x i32]* %p, i32 %add, i32 %add
44 ; CHECK: MayAlias: i32* %gep2, i64* %bc
45 define void @t5([8 x i32]* %p, i32 %addend, i32* %q) {
46 %knownnonzero = load i32, i32* %q, !range !0
47 %add = add nsw nuw i32 %addend, %knownnonzero
48 %gep1 = getelementptr [8 x i32], [8 x i32]* %p, i32 2, i32 %addend
49 %gep2 = getelementptr [8 x i32], [8 x i32]* %p, i32 2, i32 %add
50 %bc = bitcast i32* %gep1 to i64*
54 ; CHECK-LABEL: Function: add_non_zero_simple
55 ; CHECK: NoAlias: i32* %gep1, i32* %gep2
56 define void @add_non_zero_simple(i32* %p, i32 %addend, i32* %q) {
57 %knownnonzero = load i32, i32* %q, !range !0
58 %add = add i32 %addend, %knownnonzero
59 %gep1 = getelementptr i32, i32* %p, i32 %addend
60 %gep2 = getelementptr i32, i32* %p, i32 %add
64 ; CHECK-LABEL: Function: add_non_zero_different_scales
65 ; CHECK: MayAlias: i16* %gep2, i32* %gep1
66 define void @add_non_zero_different_scales(i32* %p, i32 %addend, i32* %q) {
67 %knownnonzero = load i32, i32* %q, !range !0
68 %add = add i32 %addend, %knownnonzero
69 %p16 = bitcast i32* %p to i16*
70 %gep1 = getelementptr i32, i32* %p, i32 %addend
71 %gep2 = getelementptr i16, i16* %p16, i32 %add
75 ; CHECK-LABEL: Function: add_non_zero_different_sizes
76 ; CHECK: NoAlias: i16* %gep1.16, i32* %gep2
77 ; CHECK: NoAlias: i16* %gep2.16, i32* %gep1
78 ; CHECK: NoAlias: i16* %gep1.16, i16* %gep2.16
79 ; CHECK: MayAlias: i32* %gep2, i64* %gep1.64
80 ; CHECK: MayAlias: i16* %gep2.16, i64* %gep1.64
81 ; CHECK: MayAlias: i32* %gep1, i64* %gep2.64
82 ; CHECK: MayAlias: i16* %gep1.16, i64* %gep2.64
83 ; CHECK: MayAlias: i64* %gep1.64, i64* %gep2.64
84 define void @add_non_zero_different_sizes(i32* %p, i32 %addend, i32* %q) {
85 %knownnonzero = load i32, i32* %q, !range !0
86 %add = add i32 %addend, %knownnonzero
87 %gep1 = getelementptr i32, i32* %p, i32 %addend
88 %gep2 = getelementptr i32, i32* %p, i32 %add
89 %gep1.16 = bitcast i32* %gep1 to i16*
90 %gep2.16 = bitcast i32* %gep2 to i16*
91 %gep1.64 = bitcast i32* %gep1 to i64*
92 %gep2.64 = bitcast i32* %gep2 to i64*
97 ; CHECK-LABEL: add_non_zero_with_offset
98 ; MayAlias: i32* %gep1, i32* %gep2
99 ; NoAlias: i16* %gep1.16, i16* %gep2.16
100 define void @add_non_zero_with_offset(i32* %p, i32 %addend, i32* %q) {
101 %knownnonzero = load i32, i32* %q, !range !0
102 %add = add i32 %addend, %knownnonzero
103 %p.8 = bitcast i32* %p to i8*
104 %p.off.8 = getelementptr i8, i8* %p.8, i32 2
105 %p.off = bitcast i8* %p.off.8 to i32*
106 %gep1 = getelementptr i32, i32* %p.off, i32 %addend
107 %gep2 = getelementptr i32, i32* %p, i32 %add
108 %gep1.16 = bitcast i32* %gep1 to i16*
109 %gep2.16 = bitcast i32* %gep2 to i16*
113 ; CHECK-LABEL: Function: add_non_zero_assume
114 ; CHECK: NoAlias: i32* %gep1, i32* %gep2
115 define void @add_non_zero_assume(i32* %p, i32 %addend, i32 %knownnonzero) {
116 %cmp = icmp ne i32 %knownnonzero, 0
117 call void @llvm.assume(i1 %cmp)
118 %add = add i32 %addend, %knownnonzero
119 %gep1 = getelementptr i32, i32* %p, i32 %addend
120 %gep2 = getelementptr i32, i32* %p, i32 %add
124 ; CHECK-LABEL: non_zero_index_simple
125 ; CHECK: NoAlias: i32* %gep, i32* %p
126 ; CHECK: NoAlias: i16* %gep.16, i32* %p
127 ; CHECK: MayAlias: i32* %p, i64* %gep.64
128 define void @non_zero_index_simple(i32* %p, i32* %q) {
129 %knownnonzero = load i32, i32* %q, !range !0
130 %gep = getelementptr i32, i32* %p, i32 %knownnonzero
131 %gep.16 = bitcast i32* %gep to i16*
132 %gep.64 = bitcast i32* %gep to i64*
136 ; CHECK-LABEL: non_zero_index_with_offset
137 ; CHECK: MayAlias: i32* %gep, i32* %p
138 ; CHECK: NoAlias: i16* %gep.16, i32* %p
139 define void @non_zero_index_with_offset(i32* %p, i32* %q) {
140 %knownnonzero = load i32, i32* %q, !range !0
141 %p.8 = bitcast i32* %p to i8*
142 %p.off.8 = getelementptr i8, i8* %p.8, i32 2
143 %p.off = bitcast i8* %p.off.8 to i32*
144 %gep = getelementptr i32, i32* %p.off, i32 %knownnonzero
145 %gep.16 = bitcast i32* %gep to i16*
149 ; CHECK-LABEL: non_zero_index_assume
150 ; CHECK: NoAlias: i32* %gep, i32* %p
151 define void @non_zero_index_assume(i32* %p, i32 %knownnonzero) {
152 %cmp = icmp ne i32 %knownnonzero, 0
153 call void @llvm.assume(i1 %cmp)
154 %gep = getelementptr i32, i32* %p, i32 %knownnonzero
158 declare void @llvm.assume(i1)
160 !0 = !{ i32 1, i32 5 }