1; RUN: opt -basic-aa -aa-eval -print-all-alias-modref-info -disable-output %s 2>&1 | FileCheck %s
2
3target datalayout = "p:32:32:32"
4
5; Test cases with i64 bit GEP indices that will get truncated implicitly to 32
6; bit due to the datalayout.
7
8declare void @llvm.assume(i1)
9
10define void @mustalias_overflow_in_32_bit_constants(i8* %ptr) {
11; CHECK-LABEL: Function: mustalias_overflow_in_32_bit_constants: 3 pointers, 0 call sites
12; CHECK-NEXT:    MustAlias: i8* %gep.1, i8* %ptr
13; CHECK-NEXT:    MustAlias:    i8* %gep.2, i8* %ptr
14; CHECK-NEXT:    MustAlias:    i8* %gep.1, i8* %gep.2
15;
16  %gep.1 = getelementptr i8, i8* %ptr, i64 4294967296
17  store i8 0, i8* %gep.1
18  %gep.2 = getelementptr i8, i8* %ptr, i64 0
19  store i8 1, i8* %gep.2
20  ret void
21}
22
23define void @mustalias_overflow_in_32_with_var_index([1 x i8]* %ptr, i64 %n) {
24; CHECK-LABEL: Function: mustalias_overflow_in_32_with_var_index
25; CHECK:       MustAlias: i8* %gep.1, i8* %gep.2
26;
27  %gep.1 = getelementptr [1 x i8], [1 x i8]* %ptr, i64 %n, i64 4294967296
28  store i8 0, i8* %gep.1
29  %gep.2 = getelementptr [1 x i8], [1 x i8]* %ptr, i64 %n, i64 0
30  store i8 1, i8* %gep.2
31  ret void
32}
33
34define void @noalias_overflow_in_32_bit_constants(i8* %ptr) {
35; CHECK-LABEL: Function: noalias_overflow_in_32_bit_constants: 3 pointers, 0 call sites
36; CHECK-NEXT:    MustAlias: i8* %gep.1, i8* %ptr
37; CHECK-NEXT:    NoAlias:  i8* %gep.2, i8* %ptr
38; CHECK-NEXT:    NoAlias:  i8* %gep.1, i8* %gep.2
39;
40  %gep.1 = getelementptr i8, i8* %ptr, i64 4294967296
41  store i8 0, i8* %gep.1
42  %gep.2 = getelementptr i8, i8* %ptr, i64 1
43  store i8 1, i8* %gep.2
44  ret void
45}
46
47; The GEP indices get implicitly truncated to 32 bit, so multiples of 2^32
48; (=4294967296) will be 0.
49; See https://alive2.llvm.org/ce/z/HHjQgb.
50define void @mustalias_overflow_in_32_bit_add_mul_gep(i8* %ptr, i64 %i) {
51; CHECK-LABEL: Function: mustalias_overflow_in_32_bit_add_mul_gep: 3 pointers, 1 call sites
52; CHECK-NEXT:    MayAlias: i8* %gep.1, i8* %ptr
53; CHECK-NEXT:    MayAlias: i8* %gep.2, i8* %ptr
54; CHECK-NEXT:    MayAlias: i8* %gep.1, i8* %gep.2
55;
56  %s.1 = icmp sgt i64 %i, 0
57  call void @llvm.assume(i1 %s.1)
58
59  %mul = mul nuw nsw i64 %i, 4294967296
60  %add = add nuw nsw i64 %mul, %i
61  %gep.1 = getelementptr i8, i8* %ptr, i64 %add
62  store i8 0, i8* %gep.1
63  %gep.2 = getelementptr i8, i8* %ptr, i64 %i
64  store i8 1, i8* %gep.2
65  ret void
66}
67
68define void @mayalias_overflow_in_32_bit_non_zero(i8* %ptr, i64 %n) {
69; CHECK-LABEL: Function: mayalias_overflow_in_32_bit_non_zero
70; CHECK:    MayAlias: i8* %gep, i8* %ptr
71;
72  %c = icmp ne i64 %n, 0
73  call void @llvm.assume(i1 %c)
74  store i8 0, i8* %ptr
75  %gep = getelementptr i8, i8* %ptr, i64 %n
76  store i8 1, i8* %gep
77  ret void
78}
79
80define void @mayalias_overflow_in_32_bit_positive(i8* %ptr, i64 %n) {
81; CHECK-LABEL: Function: mayalias_overflow_in_32_bit_positive
82; CHECK:    NoAlias: i8* %gep.1, i8* %ptr
83; CHECK:    MayAlias: i8* %gep.2, i8* %ptr
84; CHECK:    MayAlias: i8* %gep.1, i8* %gep.2
85;
86  %c = icmp sgt i64 %n, 0
87  call void @llvm.assume(i1 %c)
88  %gep.1 = getelementptr i8, i8* %ptr, i64 -1
89  store i8 0, i8* %gep.1
90  %gep.2 = getelementptr i8, i8* %ptr, i64 %n
91  store i8 1, i8* %gep.2
92  ret void
93}
94