[llvm] [LAA] Support different strides & non constant dep distances using SCEV. (PR #88039)
Michael Kruse via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 16 05:47:16 PDT 2024
================
@@ -2028,68 +2029,105 @@ MemoryDepChecker::Dependence::DepType MemoryDepChecker::isDependent(
if (std::holds_alternative<Dependence::DepType>(Res))
return std::get<Dependence::DepType>(Res);
- const auto &[Dist, Stride, TypeByteSize, AIsWrite, BIsWrite] =
+ const auto &[Dist, StrideA, StrideB, TypeByteSize, AIsWrite, BIsWrite] =
std::get<DepDistanceStrideAndSizeInfo>(Res);
bool HasSameSize = TypeByteSize > 0;
+ uint64_t CommonStride = StrideA == StrideB ? StrideA : 0;
+ if (isa<SCEVCouldNotCompute>(Dist)) {
+ FoundNonConstantDistanceDependence |= CommonStride;
+ LLVM_DEBUG(dbgs() << "LAA: Dependence because of uncomputable distance.\n");
+ return Dependence::Unknown;
+ }
+
ScalarEvolution &SE = *PSE.getSE();
auto &DL = InnermostLoop->getHeader()->getModule()->getDataLayout();
- if (!isa<SCEVCouldNotCompute>(Dist) && HasSameSize &&
+ if (HasSameSize && CommonStride &&
isSafeDependenceDistance(DL, SE, *(PSE.getBackedgeTakenCount()), *Dist,
- Stride, TypeByteSize))
+ CommonStride, TypeByteSize))
return Dependence::NoDep;
const SCEVConstant *C = dyn_cast<SCEVConstant>(Dist);
- if (!C) {
- LLVM_DEBUG(dbgs() << "LAA: Dependence because of non-constant distance\n");
- FoundNonConstantDistanceDependence = true;
- return Dependence::Unknown;
- }
-
- const APInt &Val = C->getAPInt();
- int64_t Distance = Val.getSExtValue();
// Attempt to prove strided accesses independent.
- if (std::abs(Distance) > 0 && Stride > 1 && HasSameSize &&
- areStridedAccessesIndependent(std::abs(Distance), Stride, TypeByteSize)) {
- LLVM_DEBUG(dbgs() << "LAA: Strided accesses are independent\n");
- return Dependence::NoDep;
+ if (C) {
+ const APInt &Val = C->getAPInt();
+ int64_t Distance = Val.getSExtValue();
+
+ if (std::abs(Distance) > 0 && CommonStride > 1 && HasSameSize &&
+ areStridedAccessesIndependent(std::abs(Distance), CommonStride,
+ TypeByteSize)) {
+ LLVM_DEBUG(dbgs() << "LAA: Strided accesses are independent\n");
+ return Dependence::NoDep;
+ }
+
+ // Write to the same location with the same size.
+ if (C->isZero()) {
+ if (HasSameSize)
+ return Dependence::Forward;
+ LLVM_DEBUG(
+ dbgs()
+ << "LAA: Zero dependence difference but different type sizes\n");
+ return Dependence::Unknown;
+ }
}
// Negative distances are not plausible dependencies.
- if (Val.isNegative()) {
+ if (SE.isKnownNonPositive(Dist)) {
+ if (!SE.isKnownNegative(Dist) && !HasSameSize) {
+ LLVM_DEBUG(dbgs() << "LAA: possibly zero dependence difference but "
+ "different type sizes\n");
+ return Dependence::Unknown;
+ }
----------------
Meinersbur wrote:
My impression is that most of these `return Unknown;` should fall through instead to give other checks a chance to match. If there is an invariant after a certain point (e.g. "type size is equal") is should be rejected there. It avoids having to maintain several conditions e.g. updating `FoundNonConstantDistanceDependence` which seems to be missing here as well.
https://github.com/llvm/llvm-project/pull/88039
More information about the llvm-commits
mailing list