From 78eb09629d960fa4fba8570d84e78c840ac3f3c0 Mon Sep 17 00:00:00 2001 From: Florian Hahn Date: Wed, 30 Jun 2021 18:00:36 +0100 Subject: [PATCH] [BasicAA] Add test for incorrectly inferring noalias due to scale sign. This patch adds a test where we currently incorrectly determine noalias, because the sign of Scale is adjusted after 91fa3565da16. --- test/Analysis/BasicAA/gep-modulo.ll | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/test/Analysis/BasicAA/gep-modulo.ll b/test/Analysis/BasicAA/gep-modulo.ll index e009ce498b0..cf75ba5101b 100644 --- a/test/Analysis/BasicAA/gep-modulo.ll +++ b/test/Analysis/BasicAA/gep-modulo.ll @@ -273,3 +273,32 @@ define void @may_overflow_pointer_diff([16 x i8]* %ptr, i64 %idx) { ret void } + +; %gep.1 and %gep.idx may alias, e.g. if %idx.1 = 8 and %idx.2 == 2. %gep.idx is then +; (((18446744073709551614 * 8) % 2^64 + 6 * 2) % 2^64 + 10) % 2^64 == 6. +define void @may_overflow_mul_scale_neg([200 x [ 6 x i8]]* %ptr, i64 %idx.1,i64 %idx.2) { +; CHECK-LABEL: Function: may_overflow_mul_scale_neg: 4 pointers, 2 call sites +; CHECK-NEXT: MustAlias: [200 x [6 x i8]]* %ptr, i8* %bc +; CHECK-NEXT: PartialAlias (off 6): [200 x [6 x i8]]* %ptr, i8* %gep.1 +; CHECK-NEXT: NoAlias: i8* %bc, i8* %gep.1 +; CHECK-NEXT: MayAlias: [200 x [6 x i8]]* %ptr, i8* %gep.idx +; CHECK-NEXT: NoAlias: i8* %bc, i8* %gep.idx +; CHECK-NEXT: NoAlias: i8* %gep.1, i8* %gep.idx +; + %idx.1.pos = icmp sge i64 %idx.1, 0 + call void @llvm.assume(i1 %idx.1.pos) + %idx.2.pos = icmp sge i64 %idx.2, 0 + call void @llvm.assume(i1 %idx.2.pos) + + %bc = bitcast [ 200 x [ 6 x i8 ] ]* %ptr to i8* + %gep.1 = getelementptr i8, i8* %bc, i64 6 + store i8 1, i8* %gep.1, align 1 + + %mul.0 = mul i64 %idx.1, -2 + %add = add i64 %mul.0, 10 + %gep.idx = getelementptr [ 200 x [ 6 x i8 ] ], [ 200 x [ 6 x i8 ] ]* %ptr, i64 0, i64 %idx.2, i64 %add + store i8 0, i8* %gep.idx, align 1 + ret void +} + +declare void @llvm.assume(i1)