322 lines · plain
1; RUN: opt < %s -aa-pipeline=basic-aa -passes=aa-eval -print-all-alias-modref-info -disable-output 2>&1 | FileCheck %s2target 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_zext6; CHECK: NoAlias: i8* %a, i8* %b7 8define void @test_with_zext() {9 %1 = tail call ptr @malloc(i64 120)10 %a = getelementptr inbounds i8, ptr %1, i64 811 %2 = getelementptr inbounds i8, ptr %1, i64 1612 %3 = zext i32 3 to i6413 %b = getelementptr inbounds i8, ptr %2, i64 %314 load i8, ptr %a15 load i8, ptr %b16 ret void17}18 19; CHECK-LABEL: test_with_lshr20; CHECK: NoAlias: i8* %a, i8* %b21 22define void @test_with_lshr(i64 %i) {23 %1 = tail call ptr @malloc(i64 120)24 %a = getelementptr inbounds i8, ptr %1, i64 825 %2 = getelementptr inbounds i8, ptr %1, i64 1626 %3 = lshr i64 %i, 227 %b = getelementptr inbounds i8, ptr %2, i64 %328 load i8, ptr %a29 load i8, ptr %b30 ret void31}32 33; CHECK-LABEL: test_with_lshr_different_sizes34; CHECK: NoAlias: i8* %m1, i16* %m2.idx35 36define void @test_with_lshr_different_sizes(i64 %i) {37 %m0 = tail call ptr @malloc(i64 120)38 %m1 = getelementptr inbounds i8, ptr %m0, i64 139 load i8, ptr %m140 %m2 = getelementptr inbounds i8, ptr %m0, i64 241 %idx = lshr i64 %i, 242 %m2.idx = getelementptr inbounds i16, ptr %m2, i64 %idx43 load i16, ptr %m2.idx44 ret void45}46 47; CHECK-LABEL: test_with_a_loop48; CHECK: NoAlias: i8* %a, i8* %b49 50define void @test_with_a_loop(ptr %mem) {51 br label %for.loop52 53for.loop:54 %i = phi i32 [ 0, %0 ], [ %i.plus1, %for.loop ]55 %a = getelementptr inbounds i8, ptr %mem, i64 856 load i8, ptr %a57 %a.plus1 = getelementptr inbounds i8, ptr %mem, i64 1658 %i.64 = zext i32 %i to i6459 %b = getelementptr inbounds i8, ptr %a.plus1, i64 %i.6460 load i8, ptr %b61 %i.plus1 = add nuw nsw i32 %i, 162 %cmp = icmp eq i32 %i.plus1, 1063 br i1 %cmp, label %for.loop.exit, label %for.loop64 65for.loop.exit:66 ret void67}68 69; CHECK-LABEL: test_with_varying_base_pointer_in_loop70; CHECK: NoAlias: i8* %a, i8* %b71 72define void @test_with_varying_base_pointer_in_loop(ptr %mem.orig) {73 br label %for.loop74 75for.loop:76 %mem = phi ptr [ %mem.orig, %0 ], [ %mem.plus1, %for.loop ]77 %i = phi i32 [ 0, %0 ], [ %i.plus1, %for.loop ]78 %a = getelementptr inbounds i8, ptr %mem, i64 879 load i8, ptr %a80 %a.plus1 = getelementptr inbounds i8, ptr %mem, i64 1681 %i.64 = zext i32 %i to i6482 %b = getelementptr inbounds i8, ptr %a.plus1, i64 %i.6483 load i8, ptr %b84 %i.plus1 = add nuw nsw i32 %i, 185 %mem.plus1 = getelementptr inbounds i8, ptr %mem, i64 886 %cmp = icmp eq i32 %i.plus1, 1087 br i1 %cmp, label %for.loop.exit, label %for.loop88 89for.loop.exit:90 ret void91}92 93; CHECK-LABEL: test_sign_extension94; CHECK: MayAlias: i8* %a, i64* %b.i895 96define void @test_sign_extension(i32 %p) {97 %1 = tail call ptr @malloc(i64 120)98 %p.64 = zext i32 %p to i6499 %a = getelementptr inbounds i8, ptr %1, i64 %p.64100 load i8, ptr %a101 %p.minus1 = add i32 %p, -1102 %p.minus1.64 = zext i32 %p.minus1 to i64103 %b.i8 = getelementptr inbounds i8, ptr %1, i64 %p.minus1.64104 load i64, ptr %b.i8105 ret void106}107 108; CHECK-LABEL: test_fe_tools109; CHECK: MayAlias: i32* %a, i32* %b110 111define void @test_fe_tools(ptr %values) {112 br label %reorder113 114for.loop:115 %i = phi i32 [ 0, %reorder ], [ %i.next, %for.loop ]116 %idxprom = zext i32 %i to i64117 %b = getelementptr inbounds [8 x i32], ptr %values, i64 0, i64 %idxprom118 load i32, ptr %b119 %i.next = add nuw nsw i32 %i, 1120 %cmp = icmp eq i32 %i.next, 10121 br i1 %cmp, label %for.loop.exit, label %for.loop122 123reorder:124 %a = getelementptr inbounds [8 x i32], ptr %values, i64 0, i64 1125 load i32, ptr %a126 br label %for.loop127 128for.loop.exit:129 ret void130}131 132@b = global i32 0, align 4133@d = global i32 0, align 4134 135; CHECK-LABEL: test_spec2006136; CHECK: MayAlias: ptr* %x, ptr* %y137 138define void @test_spec2006() {139 %h = alloca [1 x [2 x ptr]], align 16140 %d.val = load i32, ptr @d, align 4141 %d.promoted = sext i32 %d.val to i64142 %1 = icmp slt i32 %d.val, 2143 br i1 %1, label %.lr.ph, label %bb3144 145.lr.ph: ; preds = %0146 br label %bb2147 148bb2:149 %i = phi i32 [ %d.val, %.lr.ph ], [ %i.plus1, %bb2 ]150 %i.promoted = sext i32 %i to i64151 %x = getelementptr inbounds [1 x [2 x ptr]], ptr %h, i64 0, i64 %d.promoted, i64 %i.promoted152 load ptr, ptr %x153 %i.plus1 = add nsw i32 %i, 1154 %cmp = icmp slt i32 %i.plus1, 2155 br i1 %cmp, label %bb2, label %bb3156 157bb3:158 %y = getelementptr inbounds [1 x [2 x ptr]], ptr %h, i64 0, i64 0, i64 1159 load ptr, ptr %y160 ret void161}162 163; CHECK-LABEL: test_modulo_analysis_easy_case164; CHECK: NoAlias: ptr* %x, ptr* %y165 166define void @test_modulo_analysis_easy_case(i64 %i) {167 %h = alloca [1 x [2 x ptr]], align 16168 %x = getelementptr inbounds [1 x [2 x ptr]], ptr %h, i64 0, i64 %i, i64 0169 %y = getelementptr inbounds [1 x [2 x ptr]], ptr %h, i64 0, i64 0, i64 1170 load ptr, ptr %x171 load ptr, ptr %y172 ret void173}174 175; CHECK-LABEL: test_modulo_analysis_in_loop176; CHECK: NoAlias: ptr* %x, ptr* %y177 178define void @test_modulo_analysis_in_loop() {179 %h = alloca [1 x [2 x ptr]], align 16180 br label %for.loop181 182for.loop:183 %i = phi i32 [ 0, %0 ], [ %i.plus1, %for.loop ]184 %i.promoted = sext i32 %i to i64185 %x = getelementptr inbounds [1 x [2 x ptr]], ptr %h, i64 0, i64 %i.promoted, i64 0186 %y = getelementptr inbounds [1 x [2 x ptr]], ptr %h, i64 0, i64 0, i64 1187 load ptr, ptr %x188 load ptr, ptr %y189 %i.plus1 = add nsw i32 %i, 1190 %cmp = icmp slt i32 %i.plus1, 2191 br i1 %cmp, label %for.loop, label %for.loop.exit192 193for.loop.exit:194 ret void195}196 197; CHECK-LABEL: test_modulo_analysis_with_global198; CHECK: MayAlias: ptr* %x, ptr* %y199 200define void @test_modulo_analysis_with_global() {201 %h = alloca [1 x [2 x ptr]], align 16202 %b = load i32, ptr @b, align 4203 %b.promoted = sext i32 %b to i64204 br label %for.loop205 206for.loop:207 %i = phi i32 [ 0, %0 ], [ %i.plus1, %for.loop ]208 %i.promoted = sext i32 %i to i64209 %x = getelementptr inbounds [1 x [2 x ptr]], ptr %h, i64 0, i64 %i.promoted, i64 %b.promoted210 %y = getelementptr inbounds [1 x [2 x ptr]], ptr %h, i64 0, i64 0, i64 1211 load ptr, ptr %x212 load ptr, ptr %y213 %i.plus1 = add nsw i32 %i, 1214 %cmp = icmp slt i32 %i.plus1, 2215 br i1 %cmp, label %for.loop, label %for.loop.exit216 217for.loop.exit:218 ret void219}220 221; CHECK-LABEL: test_const_eval222; CHECK: NoAlias: i8* %a, i8* %b223define void @test_const_eval(ptr %ptr, i64 %offset) {224 %a = getelementptr inbounds i8, ptr %ptr, i64 %offset225 %a.dup = getelementptr inbounds i8, ptr %ptr, i64 %offset226 %three = zext i32 3 to i64227 %b = getelementptr inbounds i8, ptr %a.dup, i64 %three228 load i8, ptr %a229 load i8, ptr %b230 ret void231}232 233; CHECK-LABEL: test_const_eval_scaled234; CHECK: MustAlias: i8* %a, i8* %b235define void @test_const_eval_scaled(ptr %ptr) {236 %three = zext i32 3 to i64237 %six = mul i64 %three, 2238 %a = getelementptr inbounds i8, ptr %ptr, i64 %six239 %b = getelementptr inbounds i8, ptr %ptr, i64 6240 load i8, ptr %a241 load i8, ptr %b242 ret void243}244 245; CHECK-LABEL: Function: foo246; CHECK: MustAlias: float* %arrayidx, float* %arrayidx4.84247define float @foo(ptr %A, float %rend, ptr %wayar) {248entry:249 %x0 = load i32, ptr %A, align 4250 %conv = sext i32 %x0 to i64251 %mul = shl nsw i64 %conv, 3252 %call = tail call ptr @malloc(i64 %mul)253 254 %sub = add nsw i32 %x0, -1255 %idxprom = sext i32 %sub to i64256 %arrayidx = getelementptr inbounds float, ptr %call, i64 %idxprom257 store float %rend, ptr %arrayidx, align 8258 259 %indvars.iv76.83 = add nsw i64 %conv, -1260 %arrayidx4.84 = getelementptr inbounds float, ptr %call, i64 %indvars.iv76.83261 %x4 = load float, ptr %arrayidx4.84, align 8262 263 ret float %x4264}265 266; CHECK-LABEL: Function: test_shl_nuw_zext267; CHECK: MustAlias: i8* %p.1, i8* %p.2268define void @test_shl_nuw_zext(ptr %p, i32 %x) {269 %shl = shl nuw i32 %x, 1270 %shl.ext = zext i32 %shl to i64271 %ext = zext i32 %x to i64272 %ext.shl = shl nuw i64 %ext, 1273 %p.1 = getelementptr i8, ptr %p, i64 %shl.ext274 %p.2 = getelementptr i8, ptr %p, i64 %ext.shl275 load i8, ptr %p.1276 load i8, ptr %p.2277 ret void278}279 280; CHECK-LABEL: Function: test_shl_nsw_sext281; CHECK: MustAlias: i8* %p.1, i8* %p.2282define void @test_shl_nsw_sext(ptr %p, i32 %x) {283 %shl = shl nsw i32 %x, 1284 %shl.ext = sext i32 %shl to i64285 %ext = sext i32 %x to i64286 %ext.shl = shl nsw i64 %ext, 1287 %p.1 = getelementptr i8, ptr %p, i64 %shl.ext288 %p.2 = getelementptr i8, ptr %p, i64 %ext.shl289 load i8, ptr %p.1290 load i8, ptr %p.2291 ret void292}293 294; CHECK-LABEL: Function: test_implicit_sext295; CHECK: MayAlias: i8* %p.1, i8* %p.2296define void @test_implicit_sext(ptr %p, i32 %x) {297 %add = add i32 %x, 1298 %ext = sext i32 %x to i64299 %ext.add = add i64 %ext, 1300 %p.1 = getelementptr i8, ptr %p, i32 %add301 %p.2 = getelementptr i8, ptr %p, i64 %ext.add302 load i8, ptr %p.1303 load i8, ptr %p.2304 ret void305}306 307; CHECK-LABEL: Function: test_partial_decomposition308; CHECK: MustAlias: i8* %p.1, i8* %p.2309define void @test_partial_decomposition(ptr %p, i32 %x) {310 %add = add i32 %x, 1311 %add.1 = add nsw i32 %add, 1312 %add.2 = add nsw i32 %add, 1313 %p.1 = getelementptr i8, ptr %p, i32 %add.1314 %p.2 = getelementptr i8, ptr %p, i32 %add.2315 load i8, ptr %p.1316 load i8, ptr %p.2317 ret void318}319 320; Function Attrs: nounwind321declare noalias ptr @malloc(i64)322