Skip to content

Commit 5e6b4be

Browse files
authored
[BasicAA] Treat different VScale intrinsics as the same value. (#81152)
The IR may contain multiple llvm.vscale intrinsics that have not been CSEd. This patch ensures that multiple vscales can be treated the same, either in the decomposition of geps and when we subtract one decomposition from another.
1 parent 0c63453 commit 5e6b4be

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

llvm/lib/Analysis/BasicAliasAnalysis.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,12 @@ static bool isObjectSize(const Value *V, TypeSize Size, const DataLayout &DL,
188188
return ObjectSize && *ObjectSize == Size;
189189
}
190190

191+
/// Return true if both V1 and V2 are VScale
192+
static bool areBothVScale(const Value *V1, const Value *V2) {
193+
return PatternMatch::match(V1, PatternMatch::m_VScale()) &&
194+
PatternMatch::match(V2, PatternMatch::m_VScale());
195+
}
196+
191197
//===----------------------------------------------------------------------===//
192198
// CaptureInfo implementations
193199
//===----------------------------------------------------------------------===//
@@ -679,7 +685,8 @@ BasicAAResult::DecomposeGEPExpression(const Value *V, const DataLayout &DL,
679685
// A[x][x] -> x*16 + x*4 -> x*20
680686
// This also ensures that 'x' only appears in the index list once.
681687
for (unsigned i = 0, e = Decomposed.VarIndices.size(); i != e; ++i) {
682-
if (Decomposed.VarIndices[i].Val.V == LE.Val.V &&
688+
if ((Decomposed.VarIndices[i].Val.V == LE.Val.V ||
689+
areBothVScale(Decomposed.VarIndices[i].Val.V, LE.Val.V)) &&
683690
Decomposed.VarIndices[i].Val.hasSameCastsAs(LE.Val)) {
684691
Scale += Decomposed.VarIndices[i].Scale;
685692
LE.IsNSW = false; // We cannot guarantee nsw for the merge.
@@ -1792,7 +1799,8 @@ void BasicAAResult::subtractDecomposedGEPs(DecomposedGEP &DestGEP,
17921799
bool Found = false;
17931800
for (auto I : enumerate(DestGEP.VarIndices)) {
17941801
VariableGEPIndex &Dest = I.value();
1795-
if (!isValueEqualInPotentialCycles(Dest.Val.V, Src.Val.V, AAQI) ||
1802+
if ((!isValueEqualInPotentialCycles(Dest.Val.V, Src.Val.V, AAQI) &&
1803+
!areBothVScale(Dest.Val.V, Src.Val.V)) ||
17961804
!Dest.Val.hasSameCastsAs(Src.Val))
17971805
continue;
17981806

llvm/test/Analysis/BasicAA/vscale.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -488,9 +488,9 @@ define void @onevscale(ptr %p) vscale_range(1,16) {
488488
}
489489

490490
; CHECK-LABEL: twovscales
491-
; CHECK-DAG: MayAlias: <vscale x 4 x i32>* %vp161, <vscale x 4 x i32>* %vp162
491+
; CHECK-DAG: MustAlias: <vscale x 4 x i32>* %vp161, <vscale x 4 x i32>* %vp162
492492
; CHECK-DAG: NoAlias: <vscale x 4 x i32>* %vp161, <vscale x 4 x i32>* %vp161b
493-
; CHECK-DAG: MayAlias: <vscale x 4 x i32>* %vp161b, <vscale x 4 x i32>* %vp162
493+
; CHECK-DAG: NoAlias: <vscale x 4 x i32>* %vp161b, <vscale x 4 x i32>* %vp162
494494
define void @twovscales(ptr %p) vscale_range(1,16) {
495495
%v1 = call i64 @llvm.vscale.i64()
496496
%v2 = call i64 @llvm.vscale.i64()

0 commit comments

Comments
 (0)