brintos

brintos / llvm-project-archived public Read only

0
0
Text · 7.8 KiB · a5f1c1c Raw
318 lines · plain
1; RUN: opt < %s -aa-pipeline=basic-aa -passes=aa-eval -print-all-alias-modref-info -disable-output 2>&1 | FileCheck %s2 3; CHECK-LABEL: test_no_lower_bound4;5; CHECK-DAG: MayAlias: i32* %a, i32* %b6define void @test_no_lower_bound(ptr %p, i64 %i) {7  %a = getelementptr i8, ptr %p, i64 48  %b = getelementptr nuw i8, ptr %p, i64 %i9 10  load i32, ptr %a11  load i32, ptr %b12 13  ret void14}15 16; CHECK-LABEL: test_lower_bound_lt_size17;18; CHECK-DAG: MayAlias: i32* %a, i32* %b19define void @test_lower_bound_lt_size(ptr %p, i64 %i) {20  %a = getelementptr i8, ptr %p21  %add = getelementptr nuw i8, ptr %p, i64 222  %b = getelementptr nuw i8, ptr %add, i64 %i23 24  load i32, ptr %a25  load i32, ptr %b26 27  ret void28}29 30; CHECK-LABEL: test_lower_bound_ge_size31;32; CHECK-DAG: NoAlias: i32* %a, i32* %b33define void @test_lower_bound_ge_size(ptr %p, i64 %i) {34  %a = getelementptr i8, ptr %p35  %add = getelementptr nuw i8, ptr %p, i64 436  %b = getelementptr nuw i8, ptr %add, i64 %i37 38  load i32, ptr %a39  load i32, ptr %b40 41  ret void42}43 44; CHECK-LABEL: test_not_all_nuw45;46; If part of the addressing is done with non-nuw GEPs, we can't use properties47; implied by the last GEP with the whole offset. In this case, the calculation48; of %add (%p + 4) could wrap the pointer index type, such that %add +<nuw> %i49; could still alias with %p.50;51; CHECK-DAG: MayAlias: i32* %a, i32* %b52define void @test_not_all_nuw(ptr %p, i64 %i) {53  %a = getelementptr i8, ptr %p54  %add = getelementptr i8, ptr %p, i64 455  %b = getelementptr nuw i8, ptr %add, i64 %i56 57  load i32, ptr %a58  load i32, ptr %b59 60  ret void61}62 63; CHECK-LABEL: test_multi_step_not_all_nuw64;65; CHECK-DAG: MayAlias: i32* %a, i32* %b66define void @test_multi_step_not_all_nuw(ptr %p, i64 %i, i64 %j, i64 %k) {67  %a = getelementptr i8, ptr %p68  %add = getelementptr i8, ptr %p, i64 469  %step1 = getelementptr i8, ptr %add, i64 %i70  %step2 = getelementptr i8, ptr %step1, i64 %j71  %b = getelementptr nuw i8, ptr %step2, i64 %k72 73  load i32, ptr %a74  load i32, ptr %b75 76  ret void77}78 79; CHECK-LABEL: test_multi_step_all_nuw80;81; CHECK-DAG: NoAlias: i32* %a, i32* %b82define void @test_multi_step_all_nuw(ptr %p, i64 %i, i64 %j, i64 %k) {83  %a = getelementptr i8, ptr %p84  %add = getelementptr nuw i8, ptr %p, i64 485  %step1 = getelementptr nuw i8, ptr %add, i64 %i86  %step2 = getelementptr nuw i8, ptr %step1, i64 %j87  %b = getelementptr nuw i8, ptr %step2, i64 %k88 89  load i32, ptr %a90  load i32, ptr %b91 92  ret void93}94 95%struct = type { i64, [2 x i32], i64 }96 97; CHECK-LABEL: test_struct_no_nuw98;99; The array access may alias with the struct elements before and after, because100; we cannot prove that (%arr + %i) does not alias with the base pointer %p.101;102; CHECK-DAG: MayAlias: i32* %arrayidx, i64* %st103; CHECK-DAG: NoAlias: i64* %after, i64* %st104; CHECK-DAG: MayAlias: i64* %after, i32* %arrayidx105 106define void @test_struct_no_nuw(ptr %st, i64 %i) {107  %arr = getelementptr i8, ptr %st, i64 8108  %arrayidx = getelementptr [2 x i32], ptr %arr, i64 0, i64 %i109  %after = getelementptr i8, ptr %st, i64 16110 111  load i64, ptr %st112  load i32, ptr %arrayidx113  load i64, ptr %after114 115  ret void116}117 118; CHECK-LABEL: test_struct_nuw119;120; We can prove that the array access does not alias with struct element before,121; because we can prove that (%arr +<nuw> %i) does not wrap the pointer index122; type (add nuw). The array access may still alias with the struct element123; after, as the add nuw property does not preclude this.124;125; CHECK-DAG: NoAlias: i32* %arrayidx, i64* %st126; CHECK-DAG: NoAlias: i64* %after, i64* %st127; CHECK-DAG: MayAlias: i64* %after, i32* %arrayidx128 129define void @test_struct_nuw(ptr %st, i64 %i) {130  %arr = getelementptr nuw i8, ptr %st, i64 8131  %arrayidx = getelementptr nuw [2 x i32], ptr %arr, i64 0, i64 %i132  %after = getelementptr nuw i8, ptr %st, i64 16133 134  load i64, ptr %st135  load i32, ptr %arrayidx136  load i64, ptr %after137 138  ret void139}140 141; CHECK-LABEL: constant_offset_overflow142;143; If subtraction of constant offsets could overflow in an unsigned sense, we144; cannot prove the lower bound between the GEPs and so they may still alias.145;146; CHECK-DAG: MayAlias: i32* %a, i32* %b147 148define void @constant_offset_overflow(ptr %p, i64 %i) {149  %a = getelementptr i8, ptr %p, i64 -8150  %add = getelementptr nuw i8, ptr %p, i64 4151  %b = getelementptr nuw i8, ptr %add, i64 %i152 153  load i32, ptr %a154  load i32, ptr %b155 156  ret void157}158 159; CHECK-LABEL: equal_var_idx_noalias160;161; If GEPs have equal variable indices, we can prove NoAlias when the Scale of162; the RHS GEP is greater, as in this scenario the constant lower bound holds.163;164; CHECK-DAG: NoAlias: i32* %a, i32* %b165 166define void @equal_var_idx_noalias(ptr %p, i64 %i) {167  %a = getelementptr i8, ptr %p, i64 %i168 169  %add = getelementptr nuw i8, ptr %p, i64 4170  %b = getelementptr nuw i16, ptr %add, i64 %i171 172  load i32, ptr %a173  load i32, ptr %b174 175  ret void176}177 178; CHECK-LABEL: equal_var_idx_alias179;180; If GEPs have equal variable indices, we cannot prove NoAlias when the Scale of181; the RHS GEP is ult Scale of the LHS GEP.182;183; CHECK-DAG: MayAlias: i32* %a, i32* %b184 185define void @equal_var_idx_alias(ptr %p, i64 %i) {186  %a = getelementptr i32, ptr %p, i64 %i187 188  %add = getelementptr nuw i8, ptr %p, i64 4189  %b = getelementptr nuw i16, ptr %add, i64 %i190 191  load i32, ptr %b192  load i32, ptr %a193 194  ret void195}196 197; CHECK-LABEL: both_var_idx198;199; If the RHS GEP has unmatched variable indices, we cannot prove a constant200; lower bound between GEPs.201;202; CHECK-DAG: MayAlias: i32* %a, i32* %b203 204define void @both_var_idx(ptr %p, i64 %i, i64 %j) {205  %a = getelementptr i8, ptr %p, i64 %i206 207  %add = getelementptr nuw i8, ptr %p, i64 4208  %b = getelementptr nuw i8, ptr %add, i64 %j209 210  load i32, ptr %a211  load i32, ptr %b212 213  ret void214}215 216; CHECK-LABEL: add_no_nuw217; CHECK: MayAlias: i8* %gep, i8* %p218define i8 @add_no_nuw(ptr %p, i64 %n) {219  store i8 3, ptr %p220 221  %add = add i64 %n, 1222  %gep = getelementptr nuw i8, ptr %p, i64 %add223  %val = load i8, ptr %gep224  ret i8 %val225}226 227; CHECK-LABEL: add_nuw228; CHECK: NoAlias: i8* %gep, i8* %p229define i8 @add_nuw(ptr %p, i64 %n) {230  store i8 3, ptr %p231 232  %add = add nuw i64 %n, 1233  %gep = getelementptr nuw i8, ptr %p, i64 %add234  %val = load i8, ptr %gep235  ret i8 %val236}237 238; CHECK-LABEL: add_no_nuw239; CHECK: MayAlias: i8* %gep, i16* %p240define i8 @add_no_nuw_scale(ptr %p, i64 %n) {241  store i16 3, ptr %p242 243  %add = add i64 %n, 1244  %gep = getelementptr nuw i16, ptr %p, i64 %add245  %val = load i8, ptr %gep246  ret i8 %val247}248 249; CHECK-LABEL: add_nuw250; CHECK: NoAlias: i8* %gep, i16* %p251define i8 @add_nuw_scale(ptr %p, i64 %n) {252  store i16 3, ptr %p253 254  %add = add nuw i64 %n, 1255  %gep = getelementptr nuw i16, ptr %p, i64 %add256  %val = load i8, ptr %gep257  ret i8 %val258}259 260; CHECK-LABEL: sub_nuw261; CHECK: MayAlias: i8* %gep, i8* %p262define i8 @sub_nuw(ptr %p, i64 %n) {263  store i8 3, ptr %p264 265  %add = sub nuw i64 %n, 1266  %gep = getelementptr nuw i8, ptr %p, i64 %add267  %val = load i8, ptr %gep268  ret i8 %val269}270 271; CHECK-LABEL: mul_no_nuw272; CHECK: MayAlias: i8* %gep, i16* %p273define i8 @mul_no_nuw(ptr %p, i64 %n) {274  store i16 3, ptr %p275 276  %add = add nuw i64 %n, 1277  %mul = mul i64 %add, 2278  %gep = getelementptr nuw i8, ptr %p, i64 %mul279  %val = load i8, ptr %gep280  ret i8 %val281}282 283; CHECK-LABEL: mul_nuw284; CHECK: NoAlias: i8* %gep, i16* %p285define i8 @mul_nuw(ptr %p, i64 %n) {286  store i16 3, ptr %p287 288  %add = add nuw i64 %n, 1289  %mul = mul nuw i64 %add, 2290  %gep = getelementptr nuw i8, ptr %p, i64 %mul291  %val = load i8, ptr %gep292  ret i8 %val293}294 295; CHECK-LABEL: shl_no_nuw296; CHECK: MayAlias: i8* %gep, i16* %p297define i8 @shl_no_nuw(ptr %p, i64 %n) {298  store i16 3, ptr %p299 300  %add = add nuw i64 %n, 1301  %shl = shl i64 %add, 1302  %gep = getelementptr nuw i8, ptr %p, i64 %shl303  %val = load i8, ptr %gep304  ret i8 %val305}306 307; CHECK-LABEL: shl_nuw308; CHECK: NoAlias: i8* %gep, i16* %p309define i8 @shl_nuw(ptr %p, i64 %n) {310  store i16 3, ptr %p311 312  %add = add nuw i64 %n, 1313  %shl = shl nuw i64 %add, 1314  %gep = getelementptr nuw i8, ptr %p, i64 %shl315  %val = load i8, ptr %gep316  ret i8 %val317}318