Skip to content

Commit 399eee3

Browse files
committed
[BasicAA] Scalable offset with scalable typesize.
This patch adds a simple alias analysis check for accesses that are scalable with a offset between them that is also trivially scalable (there are no other constant/variable offsets). We essentially divide each side by vscale and are left needing to check that the offset >= typesize.
1 parent ef05b4b commit 399eee3

File tree

2 files changed

+32
-11
lines changed

2 files changed

+32
-11
lines changed

llvm/lib/Analysis/BasicAliasAnalysis.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1170,6 +1170,27 @@ AliasResult BasicAAResult::aliasGEP(
11701170
}
11711171
}
11721172

1173+
// VScale Alias Analysis - Given one scalable offset between accesses and a
1174+
// scalable typesize, we can divide each side by vscale, treating both values
1175+
// as a constant. We prove that Offset/vscale >= TypeSize/vscale.
1176+
if (DecompGEP1.VarIndices.size() == 1 && DecompGEP1.VarIndices[0].IsNSW &&
1177+
DecompGEP1.VarIndices[0].Val.TruncBits == 0 &&
1178+
DecompGEP1.Offset.isZero() &&
1179+
PatternMatch::match(DecompGEP1.VarIndices[0].Val.V,
1180+
PatternMatch::m_VScale())) {
1181+
const VariableGEPIndex &ScalableVar = DecompGEP1.VarIndices[0];
1182+
APInt Scale =
1183+
ScalableVar.IsNegated ? -ScalableVar.Scale : ScalableVar.Scale;
1184+
LocationSize VLeftSize = Scale.isNegative() ? V1Size : V2Size;
1185+
1186+
// Note that we do not check that the typesize is scalable, as vscale >= 1
1187+
// so noalias still holds so long as the dependency distance is at least as
1188+
// big as the typesize.
1189+
if (VLeftSize.hasValue() &&
1190+
Scale.uge(VLeftSize.getValue().getKnownMinValue()))
1191+
return AliasResult::NoAlias;
1192+
}
1193+
11731194
// Bail on analysing scalable LocationSize
11741195
if (V1Size.isScalable() || V2Size.isScalable())
11751196
return AliasResult::MayAlias;

llvm/test/Analysis/BasicAA/vscale.ll

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -339,15 +339,15 @@ define void @vscale_neg_notscalable(ptr %p) {
339339
}
340340

341341
; CHECK-LABEL: vscale_neg_scalable
342-
; CHECK-DAG: MayAlias: <vscale x 4 x i32>* %p, <vscale x 4 x i32>* %vm16
342+
; CHECK-DAG: NoAlias: <vscale x 4 x i32>* %p, <vscale x 4 x i32>* %vm16
343343
; CHECK-DAG: MayAlias: <vscale x 4 x i32>* %m16, <vscale x 4 x i32>* %p
344344
; CHECK-DAG: MayAlias: <vscale x 4 x i32>* %m16, <vscale x 4 x i32>* %vm16
345345
; CHECK-DAG: MayAlias: <vscale x 4 x i32>* %p, <vscale x 4 x i32>* %vm16m16
346346
; CHECK-DAG: MayAlias: <vscale x 4 x i32>* %vm16, <vscale x 4 x i32>* %vm16m16
347-
; CHECK-DAG: MayAlias: <vscale x 4 x i32>* %m16, <vscale x 4 x i32>* %vm16m16
347+
; CHECK-DAG: NoAlias: <vscale x 4 x i32>* %m16, <vscale x 4 x i32>* %vm16m16
348348
; CHECK-DAG: MayAlias: <vscale x 4 x i32>* %m16pv16, <vscale x 4 x i32>* %p
349349
; CHECK-DAG: MayAlias: <vscale x 4 x i32>* %m16pv16, <vscale x 4 x i32>* %vm16
350-
; CHECK-DAG: MayAlias: <vscale x 4 x i32>* %m16, <vscale x 4 x i32>* %m16pv16
350+
; CHECK-DAG: NoAlias: <vscale x 4 x i32>* %m16, <vscale x 4 x i32>* %m16pv16
351351
; CHECK-DAG: MayAlias: <vscale x 4 x i32>* %m16pv16, <vscale x 4 x i32>* %vm16m16
352352
define void @vscale_neg_scalable(ptr %p) {
353353
%v = call i64 @llvm.vscale.i64()
@@ -393,15 +393,15 @@ define void @vscale_pos_notscalable(ptr %p) {
393393
}
394394

395395
; CHECK-LABEL: vscale_pos_scalable
396-
; CHECK-DAG: MayAlias: <vscale x 4 x i32>* %p, <vscale x 4 x i32>* %vm16
396+
; CHECK-DAG: NoAlias: <vscale x 4 x i32>* %p, <vscale x 4 x i32>* %vm16
397397
; CHECK-DAG: MayAlias: <vscale x 4 x i32>* %m16, <vscale x 4 x i32>* %p
398398
; CHECK-DAG: MayAlias: <vscale x 4 x i32>* %m16, <vscale x 4 x i32>* %vm16
399399
; CHECK-DAG: MayAlias: <vscale x 4 x i32>* %p, <vscale x 4 x i32>* %vm16m16
400400
; CHECK-DAG: MayAlias: <vscale x 4 x i32>* %vm16, <vscale x 4 x i32>* %vm16m16
401-
; CHECK-DAG: MayAlias: <vscale x 4 x i32>* %m16, <vscale x 4 x i32>* %vm16m16
401+
; CHECK-DAG: NoAlias: <vscale x 4 x i32>* %m16, <vscale x 4 x i32>* %vm16m16
402402
; CHECK-DAG: MayAlias: <vscale x 4 x i32>* %m16pv16, <vscale x 4 x i32>* %p
403403
; CHECK-DAG: MayAlias: <vscale x 4 x i32>* %m16pv16, <vscale x 4 x i32>* %vm16
404-
; CHECK-DAG: MayAlias: <vscale x 4 x i32>* %m16, <vscale x 4 x i32>* %m16pv16
404+
; CHECK-DAG: NoAlias: <vscale x 4 x i32>* %m16, <vscale x 4 x i32>* %m16pv16
405405
; CHECK-DAG: MayAlias: <vscale x 4 x i32>* %m16pv16, <vscale x 4 x i32>* %vm16m16
406406
define void @vscale_pos_scalable(ptr %p) {
407407
%v = call i64 @llvm.vscale.i64()
@@ -421,9 +421,9 @@ define void @vscale_pos_scalable(ptr %p) {
421421

422422
; CHECK-LABEL: vscale_v1v2types
423423
; CHECK-DAG: MustAlias: <4 x i32>* %p, <vscale x 4 x i32>* %p
424-
; CHECK-DAG: MayAlias: <vscale x 4 x i32>* %p, <vscale x 4 x i32>* %vm16
425-
; CHECK-DAG: MayAlias: <4 x i32>* %p, <vscale x 4 x i32>* %vm16
426-
; CHECK-DAG: MayAlias: <vscale x 4 x i32>* %p, <4 x i32>* %vm16
424+
; CHECK-DAG: NoAlias: <vscale x 4 x i32>* %p, <vscale x 4 x i32>* %vm16
425+
; CHECK-DAG: NoAlias: <4 x i32>* %p, <vscale x 4 x i32>* %vm16
426+
; CHECK-DAG: NoAlias: <vscale x 4 x i32>* %p, <4 x i32>* %vm16
427427
; CHECK-DAG: NoAlias: <4 x i32>* %p, <4 x i32>* %vm16
428428
; CHECK-DAG: MustAlias: <4 x i32>* %vm16, <vscale x 4 x i32>* %vm16
429429
; CHECK-DAG: MayAlias: <vscale x 4 x i32>* %m16, <vscale x 4 x i32>* %p
@@ -435,8 +435,8 @@ define void @vscale_pos_scalable(ptr %p) {
435435
; CHECK-DAG: MayAlias: <4 x i32>* %m16, <vscale x 4 x i32>* %vm16
436436
; CHECK-DAG: MayAlias: <4 x i32>* %m16, <4 x i32>* %vm16
437437
; CHECK-DAG: MustAlias: <4 x i32>* %m16, <vscale x 4 x i32>* %m16
438-
; CHECK-DAG: MayAlias: <vscale x 4 x i32>* %p, <vscale x 4 x i32>* %vp16
439-
; CHECK-DAG: MayAlias: <4 x i32>* %p, <vscale x 4 x i32>* %vp16
438+
; CHECK-DAG: NoAlias: <vscale x 4 x i32>* %p, <vscale x 4 x i32>* %vp16
439+
; CHECK-DAG: NoAlias: <4 x i32>* %p, <vscale x 4 x i32>* %vp16
440440
; CHECK-DAG: MayAlias: <vscale x 4 x i32>* %vm16, <vscale x 4 x i32>* %vp16
441441
; CHECK-DAG: MayAlias: <4 x i32>* %vm16, <vscale x 4 x i32>* %vp16
442442
; CHECK-DAG: MayAlias: <vscale x 4 x i32>* %m16, <vscale x 4 x i32>* %vp16

0 commit comments

Comments
 (0)