Skip to content

Commit f88eba4

Browse files
committed
BasicAA: return more PartialAlias when scalable
Follow up on 84ea236 ([BasicAA] Handle scalable type sizes with constant offsets) to increase accuracy of BasicAA in the case of scalable sizes, returning more PartialAlias in place of MayAlias. This is done by checking that Off < (CR.Lower * LSizeMin), analogous to the non-scalable case.
1 parent 79382eb commit f88eba4

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed

llvm/lib/Analysis/BasicAliasAnalysis.cpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1210,15 +1210,19 @@ AliasResult BasicAAResult::aliasGEP(
12101210
return AR;
12111211
}
12121212
return AliasResult::NoAlias;
1213-
} else {
1214-
// We can use the getVScaleRange to prove that Off >= (CR.upper * LSize).
1215-
ConstantRange CR = getVScaleRange(&F, Off.getBitWidth());
1216-
bool Overflow;
1217-
APInt UpperRange = CR.getUnsignedMax().umul_ov(
1218-
APInt(Off.getBitWidth(), LSize.getKnownMinValue()), Overflow);
1219-
if (!Overflow && Off.uge(UpperRange))
1220-
return AliasResult::NoAlias;
12211213
}
1214+
1215+
// We can use the getVScaleRange to prove that Off >= (CR.upper * LSizeMin)
1216+
// and Off < (CR.Lower * LSizeMin).
1217+
APInt LSizeMin = APInt(Off.getBitWidth(), LSize.getKnownMinValue());
1218+
ConstantRange CR = getVScaleRange(&F, Off.getBitWidth());
1219+
bool Overflow;
1220+
APInt UpperRange = CR.getUnsignedMax().umul_ov(LSizeMin, Overflow);
1221+
if (!Overflow && Off.uge(UpperRange))
1222+
return AliasResult::NoAlias;
1223+
APInt LowerRange = CR.getUnsignedMin().umul_ov(LSizeMin, Overflow);
1224+
if (!Overflow && Off.ult(LowerRange))
1225+
return AliasResult::PartialAlias;
12221226
}
12231227

12241228
// VScale Alias Analysis - Given one scalable offset between accesses and a

llvm/test/Analysis/BasicAA/vscale.ll

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ define void @gep_alloca_const_offset_2() {
3333

3434
; CHECK-LABEL: gep_alloca_const_offset_3
3535
; CHECK-DAG: MustAlias: <vscale x 4 x i32>* %alloc, <vscale x 4 x i32>* %gep1
36-
; CHECK-DAG: MayAlias: <vscale x 4 x i32>* %alloc, i32* %gep2
37-
; CHECK-DAG: MayAlias: <vscale x 4 x i32>* %gep1, i32* %gep2
36+
; CHECK-DAG: PartialAlias: <vscale x 4 x i32>* %alloc, i32* %gep2
37+
; CHECK-DAG: PartialAlias: <vscale x 4 x i32>* %gep1, i32* %gep2
3838
define void @gep_alloca_const_offset_3() {
3939
%alloc = alloca <vscale x 4 x i32>
4040
%gep1 = getelementptr <vscale x 4 x i32>, ptr %alloc, i64 0
@@ -628,11 +628,11 @@ define void @gep_recursion_max_lookup_depth_reached(ptr %a, ptr %p) {
628628
; CHECK-DAG: MayAlias: <vscale x 4 x i32>* %noff255, <vscale x 4 x i32>* %p
629629
; CHECK-DAG: MayAlias: <vscale x 4 x i32>* %noff255, <vscale x 4 x i32>* %off255
630630
; CHECK-DAG: MayAlias: <vscale x 4 x i32>* %off256, <vscale x 4 x i32>* %p
631-
; CHECK-DAG: MayAlias: <vscale x 4 x i32>* %off255, <vscale x 4 x i32>* %off256
631+
; CHECK-DAG: PartialAlias: <vscale x 4 x i32>* %off255, <vscale x 4 x i32>* %off256
632632
; CHECK-DAG: MayAlias: <vscale x 4 x i32>* %noff255, <vscale x 4 x i32>* %off256
633633
; CHECK-DAG: MayAlias: <vscale x 4 x i32>* %noff256, <vscale x 4 x i32>* %p
634634
; CHECK-DAG: MayAlias: <vscale x 4 x i32>* %noff256, <vscale x 4 x i32>* %off255
635-
; CHECK-DAG: MayAlias: <vscale x 4 x i32>* %noff255, <vscale x 4 x i32>* %noff256
635+
; CHECK-DAG: PartialAlias: <vscale x 4 x i32>* %noff255, <vscale x 4 x i32>* %noff256
636636
; CHECK-DAG: MayAlias: <vscale x 4 x i32>* %noff256, <vscale x 4 x i32>* %off256
637637
define void @gep_2048(ptr %p) {
638638
%off255 = getelementptr i8, ptr %p, i64 255
@@ -652,11 +652,11 @@ define void @gep_2048(ptr %p) {
652652
; CHECK-DAG: MayAlias: <vscale x 4 x i32>* %noff255, <vscale x 4 x i32>* %p
653653
; CHECK-DAG: NoAlias: <vscale x 4 x i32>* %noff255, <vscale x 4 x i32>* %off255
654654
; CHECK-DAG: NoAlias: <vscale x 4 x i32>* %off256, <vscale x 4 x i32>* %p
655-
; CHECK-DAG: MayAlias: <vscale x 4 x i32>* %off255, <vscale x 4 x i32>* %off256
655+
; CHECK-DAG: PartialAlias: <vscale x 4 x i32>* %off255, <vscale x 4 x i32>* %off256
656656
; CHECK-DAG: NoAlias: <vscale x 4 x i32>* %noff255, <vscale x 4 x i32>* %off256
657657
; CHECK-DAG: NoAlias: <vscale x 4 x i32>* %noff256, <vscale x 4 x i32>* %p
658658
; CHECK-DAG: NoAlias: <vscale x 4 x i32>* %noff256, <vscale x 4 x i32>* %off255
659-
; CHECK-DAG: MayAlias: <vscale x 4 x i32>* %noff255, <vscale x 4 x i32>* %noff256
659+
; CHECK-DAG: PartialAlias: <vscale x 4 x i32>* %noff255, <vscale x 4 x i32>* %noff256
660660
; CHECK-DAG: NoAlias: <vscale x 4 x i32>* %noff256, <vscale x 4 x i32>* %off256
661661
define void @gep_2048_vscalerange(ptr %p) vscale_range(1,16) {
662662
%off255 = getelementptr i8, ptr %p, i64 255

0 commit comments

Comments
 (0)