[llvm] [DA] Fix zero coeff bug in Strong SIV test with runtime assumptions (PR #155037)
Sebastian Pop via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 9 06:17:25 PDT 2025
================
@@ -1282,7 +1282,28 @@ bool DependenceInfo::strongSIVtest(const SCEV *Coeff, const SCEV *SrcConst,
Result.DV[Level].Direction &= Dependence::DVEntry::EQ;
++StrongSIVsuccesses;
} else if (Delta->isZero()) {
- // since 0/X == 0
+ // Check if coefficient could be zero. If so, 0/0 is undefined and we
+ // cannot conclude that only same-iteration dependencies exist.
+ // When coeff=0, all iterations access the same location.
+ if (isa<SCEVUnknown>(Coeff) && !SE->isKnownNonZero(Coeff)) {
+ // Use SCEV range analysis to prove coefficient > 0 in loop context.
+ const SCEV *Zero = SE->getZero(Coeff->getType());
+
+ // Ask SCEV's range analysis if it can prove Coeff > Zero
+ if (SE->isKnownPredicate(ICmpInst::ICMP_SGT, Coeff, Zero)) {
----------------
sebpop wrote:
The check above is `!SE->isKnownNonZero(Coeff)`, so if we are here executing this condition, it is because at compile time it is not possible to know that `Coeff != 0`.
At this point we have two choices, either try another test at compile-time `Coeff > Zero` (as you said, this may be redundant with the above call to `Coeff != 0`, although from my understanding, `SE->isKnownPredicate` is using a different computation than `SE->isKnownNonZero`) or record a runtime predicate.
As Coeff is the stride of the AddRec and both source and dest strides are equal, we can have either Coeff either positive or negative. Restricting Coeff to be positive is overly conservative.
I replaced this code with testing `Coeff != 0`.
https://github.com/llvm/llvm-project/pull/155037
More information about the llvm-commits
mailing list