aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Analysis/LoopAccessAnalysis.cpp
diff options
context:
space:
mode:
authorNikita Popov <nikita.ppv@gmail.com>2021-06-23 15:57:38 +0200
committerNikita Popov <nikita.ppv@gmail.com>2021-06-23 18:44:34 +0200
commit00d3f7cc3c264adc360d0282ba8a27de2a004b94 (patch)
tree5f25dccf8d1ce290dc601e7de954214b53126e25 /llvm/lib/Analysis/LoopAccessAnalysis.cpp
parent6cc6ada143236f16faf8b383d73e00e709fa6a9f (diff)
downloadllvm-00d3f7cc3c264adc360d0282ba8a27de2a004b94.zip
llvm-00d3f7cc3c264adc360d0282ba8a27de2a004b94.tar.gz
llvm-00d3f7cc3c264adc360d0282ba8a27de2a004b94.tar.bz2
[LAA] Make getPointersDiff() API compatible with opaque pointers
Make getPointersDiff() and sortPtrAccesses() compatible with opaque pointers by explicitly passing in the element type instead of determining it from the pointer element type. The SLPVectorizer result is slightly non-optimal in that unnecessary pointer bitcasts are added. Differential Revision: https://reviews.llvm.org/D104784
Diffstat (limited to 'llvm/lib/Analysis/LoopAccessAnalysis.cpp')
-rw-r--r--llvm/lib/Analysis/LoopAccessAnalysis.cpp33
1 files changed, 20 insertions, 13 deletions
diff --git a/llvm/lib/Analysis/LoopAccessAnalysis.cpp b/llvm/lib/Analysis/LoopAccessAnalysis.cpp
index 3248b2a..9b51550 100644
--- a/llvm/lib/Analysis/LoopAccessAnalysis.cpp
+++ b/llvm/lib/Analysis/LoopAccessAnalysis.cpp
@@ -1124,16 +1124,22 @@ int64_t llvm::getPtrStride(PredicatedScalarEvolution &PSE, Value *Ptr,
return Stride;
}
-Optional<int> llvm::getPointersDiff(Value *PtrA, Value *PtrB,
- const DataLayout &DL, ScalarEvolution &SE,
- bool StrictCheck, bool CheckType) {
+Optional<int> llvm::getPointersDiff(Type *ElemTyA, Value *PtrA, Type *ElemTyB,
+ Value *PtrB, const DataLayout &DL,
+ ScalarEvolution &SE, bool StrictCheck,
+ bool CheckType) {
assert(PtrA && PtrB && "Expected non-nullptr pointers.");
+ assert(cast<PointerType>(PtrA->getType())
+ ->isOpaqueOrPointeeTypeMatches(ElemTyA) && "Wrong PtrA type");
+ assert(cast<PointerType>(PtrB->getType())
+ ->isOpaqueOrPointeeTypeMatches(ElemTyB) && "Wrong PtrB type");
+
// Make sure that A and B are different pointers.
if (PtrA == PtrB)
return 0;
- // Make sure that PtrA and PtrB have the same type if required
- if (CheckType && PtrA->getType() != PtrB->getType())
+ // Make sure that the element types are the same if required.
+ if (CheckType && ElemTyA != ElemTyB)
return None;
unsigned ASA = PtrA->getType()->getPointerAddressSpace();
@@ -1174,8 +1180,7 @@ Optional<int> llvm::getPointersDiff(Value *PtrA, Value *PtrB,
return None;
Val = Diff->getAPInt().getSExtValue();
}
- Type *Ty = cast<PointerType>(PtrA->getType())->getElementType();
- int Size = DL.getTypeStoreSize(Ty);
+ int Size = DL.getTypeStoreSize(ElemTyA);
int Dist = Val / Size;
// Ensure that the calculated distance matches the type-based one after all
@@ -1185,8 +1190,8 @@ Optional<int> llvm::getPointersDiff(Value *PtrA, Value *PtrB,
return None;
}
-bool llvm::sortPtrAccesses(ArrayRef<Value *> VL, const DataLayout &DL,
- ScalarEvolution &SE,
+bool llvm::sortPtrAccesses(ArrayRef<Value *> VL, Type *ElemTy,
+ const DataLayout &DL, ScalarEvolution &SE,
SmallVectorImpl<unsigned> &SortedIndices) {
assert(llvm::all_of(
VL, [](const Value *V) { return V->getType()->isPointerTy(); }) &&
@@ -1204,8 +1209,8 @@ bool llvm::sortPtrAccesses(ArrayRef<Value *> VL, const DataLayout &DL,
int Cnt = 1;
bool IsConsecutive = true;
for (auto *Ptr : VL.drop_front()) {
- Optional<int> Diff =
- getPointersDiff(Ptr0, Ptr, DL, SE, /*StrictCheck=*/true);
+ Optional<int> Diff = getPointersDiff(ElemTy, Ptr0, ElemTy, Ptr, DL, SE,
+ /*StrictCheck=*/true);
if (!Diff)
return false;
@@ -1238,8 +1243,10 @@ bool llvm::isConsecutiveAccess(Value *A, Value *B, const DataLayout &DL,
Value *PtrB = getLoadStorePointerOperand(B);
if (!PtrA || !PtrB)
return false;
- Optional<int> Diff =
- getPointersDiff(PtrA, PtrB, DL, SE, /*StrictCheck=*/true, CheckType);
+ Type *ElemTyA = getLoadStoreType(A);
+ Type *ElemTyB = getLoadStoreType(B);
+ Optional<int> Diff = getPointersDiff(ElemTyA, PtrA, ElemTyB, PtrB, DL, SE,
+ /*StrictCheck=*/true, CheckType);
return Diff && *Diff == 1;
}