[llvm] [LAA] Use computeConstantDifference() (PR #103725)
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 14 05:27:51 PDT 2024
https://github.com/fhahn commented:
I added the following asserts and checked some other codebases and found no missed cases. Not sure if it might be worth including such an assert to see if there are some cases where this is still causing a difference
```
diff --git a/llvm/lib/Analysis/LoopAccessAnalysis.cpp b/llvm/lib/Analysis/LoopAccessAnalysis.cpp
index 8c939f261e69..7fbc3ba53292 100644
--- a/llvm/lib/Analysis/LoopAccessAnalysis.cpp
+++ b/llvm/lib/Analysis/LoopAccessAnalysis.cpp
@@ -1601,9 +1601,14 @@ std::optional<int> llvm::getPointersDiff(Type *ElemTyA, Value *PtrA,
const SCEV *PtrSCEVB = SE.getSCEV(PtrB);
std::optional<APInt> Diff =
SE.computeConstantDifference(PtrSCEVB, PtrSCEVA);
- if (!Diff)
+ const auto *Diff2 =
+ dyn_cast<SCEVConstant>(SE.getMinusSCEV(PtrSCEVB, PtrSCEVA));
+ if (!Diff) {
+ assert(!Diff2);
return std::nullopt;
+ }
Val = Diff->getSExtValue();
+ assert(Val == Diff2->getAPInt().getSExtValue());
}
int Size = DL.getTypeStoreSize(ElemTyA);
int Dist = Val / Size;
```
https://github.com/llvm/llvm-project/pull/103725
More information about the llvm-commits
mailing list