1; RUN: opt < %s -basic-aa -aa-eval -print-all-alias-modref-info -disable-output 2>&1 | FileCheck %s 2target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128" 3target triple = "x86_64-unknown-linux-gnu" 4 5; CHECK-LABEL: test_with_zext 6; CHECK: NoAlias: i8* %a, i8* %b 7 8define void @test_with_zext() { 9 %1 = tail call i8* @malloc(i64 120) 10 %a = getelementptr inbounds i8, i8* %1, i64 8 11 %2 = getelementptr inbounds i8, i8* %1, i64 16 12 %3 = zext i32 3 to i64 13 %b = getelementptr inbounds i8, i8* %2, i64 %3 14 ret void 15} 16 17; CHECK-LABEL: test_with_lshr 18; CHECK: NoAlias: i8* %a, i8* %b 19 20define void @test_with_lshr(i64 %i) { 21 %1 = tail call i8* @malloc(i64 120) 22 %a = getelementptr inbounds i8, i8* %1, i64 8 23 %2 = getelementptr inbounds i8, i8* %1, i64 16 24 %3 = lshr i64 %i, 2 25 %b = getelementptr inbounds i8, i8* %2, i64 %3 26 ret void 27} 28 29; CHECK-LABEL: test_with_lshr_different_sizes 30; CHECK: NoAlias: i16* %m2.idx, i8* %m1 31 32define void @test_with_lshr_different_sizes(i64 %i) { 33 %m0 = tail call i8* @malloc(i64 120) 34 %m1 = getelementptr inbounds i8, i8* %m0, i64 1 35 %m2 = getelementptr inbounds i8, i8* %m0, i64 2 36 %idx = lshr i64 %i, 2 37 %m2.i16 = bitcast i8* %m2 to i16* 38 %m2.idx = getelementptr inbounds i16, i16* %m2.i16, i64 %idx 39 ret void 40} 41 42; CHECK-LABEL: test_with_a_loop 43; CHECK: NoAlias: i8* %a, i8* %b 44 45define void @test_with_a_loop(i8* %mem) { 46 br label %for.loop 47 48for.loop: 49 %i = phi i32 [ 0, %0 ], [ %i.plus1, %for.loop ] 50 %a = getelementptr inbounds i8, i8* %mem, i64 8 51 %a.plus1 = getelementptr inbounds i8, i8* %mem, i64 16 52 %i.64 = zext i32 %i to i64 53 %b = getelementptr inbounds i8, i8* %a.plus1, i64 %i.64 54 %i.plus1 = add nuw nsw i32 %i, 1 55 %cmp = icmp eq i32 %i.plus1, 10 56 br i1 %cmp, label %for.loop.exit, label %for.loop 57 58for.loop.exit: 59 ret void 60} 61 62; CHECK-LABEL: test_with_varying_base_pointer_in_loop 63; CHECK: NoAlias: i8* %a, i8* %b 64 65define void @test_with_varying_base_pointer_in_loop(i8* %mem.orig) { 66 br label %for.loop 67 68for.loop: 69 %mem = phi i8* [ %mem.orig, %0 ], [ %mem.plus1, %for.loop ] 70 %i = phi i32 [ 0, %0 ], [ %i.plus1, %for.loop ] 71 %a = getelementptr inbounds i8, i8* %mem, i64 8 72 %a.plus1 = getelementptr inbounds i8, i8* %mem, i64 16 73 %i.64 = zext i32 %i to i64 74 %b = getelementptr inbounds i8, i8* %a.plus1, i64 %i.64 75 %i.plus1 = add nuw nsw i32 %i, 1 76 %mem.plus1 = getelementptr inbounds i8, i8* %mem, i64 8 77 %cmp = icmp eq i32 %i.plus1, 10 78 br i1 %cmp, label %for.loop.exit, label %for.loop 79 80for.loop.exit: 81 ret void 82} 83 84; CHECK-LABEL: test_sign_extension 85; CHECK: MayAlias: i64* %b.i64, i8* %a 86 87define void @test_sign_extension(i32 %p) { 88 %1 = tail call i8* @malloc(i64 120) 89 %p.64 = zext i32 %p to i64 90 %a = getelementptr inbounds i8, i8* %1, i64 %p.64 91 %p.minus1 = add i32 %p, -1 92 %p.minus1.64 = zext i32 %p.minus1 to i64 93 %b.i8 = getelementptr inbounds i8, i8* %1, i64 %p.minus1.64 94 %b.i64 = bitcast i8* %b.i8 to i64* 95 ret void 96} 97 98; CHECK-LABEL: test_fe_tools 99; CHECK: MayAlias: i32* %a, i32* %b 100 101define void @test_fe_tools([8 x i32]* %values) { 102 br label %reorder 103 104for.loop: 105 %i = phi i32 [ 0, %reorder ], [ %i.next, %for.loop ] 106 %idxprom = zext i32 %i to i64 107 %b = getelementptr inbounds [8 x i32], [8 x i32]* %values, i64 0, i64 %idxprom 108 %i.next = add nuw nsw i32 %i, 1 109 %1 = icmp eq i32 %i.next, 10 110 br i1 %1, label %for.loop.exit, label %for.loop 111 112reorder: 113 %a = getelementptr inbounds [8 x i32], [8 x i32]* %values, i64 0, i64 1 114 br label %for.loop 115 116for.loop.exit: 117 ret void 118} 119 120@b = global i32 0, align 4 121@d = global i32 0, align 4 122 123; CHECK-LABEL: test_spec2006 124; CHECK: MayAlias: i32** %x, i32** %y 125 126define void @test_spec2006() { 127 %h = alloca [1 x [2 x i32*]], align 16 128 %d.val = load i32, i32* @d, align 4 129 %d.promoted = sext i32 %d.val to i64 130 %1 = icmp slt i32 %d.val, 2 131 br i1 %1, label %.lr.ph, label %3 132 133.lr.ph: ; preds = %0 134 br label %2 135 136; <label>:2 ; preds = %.lr.ph, %2 137 %i = phi i32 [ %d.val, %.lr.ph ], [ %i.plus1, %2 ] 138 %i.promoted = sext i32 %i to i64 139 %x = getelementptr inbounds [1 x [2 x i32*]], [1 x [2 x i32*]]* %h, i64 0, i64 %d.promoted, i64 %i.promoted 140 %i.plus1 = add nsw i32 %i, 1 141 %cmp = icmp slt i32 %i.plus1, 2 142 br i1 %cmp, label %2, label %3 143 144; <label>:3 ; preds = %._crit_edge, %0 145 %y = getelementptr inbounds [1 x [2 x i32*]], [1 x [2 x i32*]]* %h, i64 0, i64 0, i64 1 146 ret void 147} 148 149; CHECK-LABEL: test_modulo_analysis_easy_case 150; CHECK: NoAlias: i32** %x, i32** %y 151 152define void @test_modulo_analysis_easy_case(i64 %i) { 153 %h = alloca [1 x [2 x i32*]], align 16 154 %x = getelementptr inbounds [1 x [2 x i32*]], [1 x [2 x i32*]]* %h, i64 0, i64 %i, i64 0 155 %y = getelementptr inbounds [1 x [2 x i32*]], [1 x [2 x i32*]]* %h, i64 0, i64 0, i64 1 156 ret void 157} 158 159; CHECK-LABEL: test_modulo_analysis_in_loop 160; CHECK: NoAlias: i32** %x, i32** %y 161 162define void @test_modulo_analysis_in_loop() { 163 %h = alloca [1 x [2 x i32*]], align 16 164 br label %for.loop 165 166for.loop: 167 %i = phi i32 [ 0, %0 ], [ %i.plus1, %for.loop ] 168 %i.promoted = sext i32 %i to i64 169 %x = getelementptr inbounds [1 x [2 x i32*]], [1 x [2 x i32*]]* %h, i64 0, i64 %i.promoted, i64 0 170 %y = getelementptr inbounds [1 x [2 x i32*]], [1 x [2 x i32*]]* %h, i64 0, i64 0, i64 1 171 %i.plus1 = add nsw i32 %i, 1 172 %cmp = icmp slt i32 %i.plus1, 2 173 br i1 %cmp, label %for.loop, label %for.loop.exit 174 175for.loop.exit: 176 ret void 177} 178 179; CHECK-LABEL: test_modulo_analysis_with_global 180; CHECK: MayAlias: i32** %x, i32** %y 181 182define void @test_modulo_analysis_with_global() { 183 %h = alloca [1 x [2 x i32*]], align 16 184 %b = load i32, i32* @b, align 4 185 %b.promoted = sext i32 %b to i64 186 br label %for.loop 187 188for.loop: 189 %i = phi i32 [ 0, %0 ], [ %i.plus1, %for.loop ] 190 %i.promoted = sext i32 %i to i64 191 %x = getelementptr inbounds [1 x [2 x i32*]], [1 x [2 x i32*]]* %h, i64 0, i64 %i.promoted, i64 %b.promoted 192 %y = getelementptr inbounds [1 x [2 x i32*]], [1 x [2 x i32*]]* %h, i64 0, i64 0, i64 1 193 %i.plus1 = add nsw i32 %i, 1 194 %cmp = icmp slt i32 %i.plus1, 2 195 br i1 %cmp, label %for.loop, label %for.loop.exit 196 197for.loop.exit: 198 ret void 199} 200 201; CHECK-LABEL: test_const_eval 202; CHECK: NoAlias: i8* %a, i8* %b 203define void @test_const_eval(i8* %ptr, i64 %offset) { 204 %a = getelementptr inbounds i8, i8* %ptr, i64 %offset 205 %a.dup = getelementptr inbounds i8, i8* %ptr, i64 %offset 206 %three = zext i32 3 to i64 207 %b = getelementptr inbounds i8, i8* %a.dup, i64 %three 208 ret void 209} 210 211; CHECK-LABEL: test_const_eval_scaled 212; CHECK: MustAlias: i8* %a, i8* %b 213define void @test_const_eval_scaled(i8* %ptr) { 214 %three = zext i32 3 to i64 215 %six = mul i64 %three, 2 216 %a = getelementptr inbounds i8, i8* %ptr, i64 %six 217 %b = getelementptr inbounds i8, i8* %ptr, i64 6 218 ret void 219} 220 221; CHECK-LABEL: Function: foo 222; CHECK: MustAlias: float* %arrayidx, float* %arrayidx4.84 223define float @foo(i32 *%A, float %rend, float** %wayar) { 224entry: 225 %x0 = load i32, i32* %A, align 4 226 %conv = sext i32 %x0 to i64 227 %mul = shl nsw i64 %conv, 3 228 %call = tail call i8* @malloc(i64 %mul) 229 %x1 = bitcast i8* %call to float* 230 231 %sub = add nsw i32 %x0, -1 232 %idxprom = sext i32 %sub to i64 233 %arrayidx = getelementptr inbounds float, float* %x1, i64 %idxprom 234 store float %rend, float* %arrayidx, align 8 235 236 %indvars.iv76.83 = add nsw i64 %conv, -1 237 %arrayidx4.84 = getelementptr inbounds float, float* %x1, i64 %indvars.iv76.83 238 %x4 = load float, float* %arrayidx4.84, align 8 239 240 ret float %x4 241} 242 243; Function Attrs: nounwind 244declare noalias i8* @malloc(i64) 245