[llvm] [LAA] Speculate the interleave factor for strided pointer inductions (PR #216036)
Ramkumar Ramachandra via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 13 07:32:46 PDT 2026
================
@@ -198,6 +198,28 @@ m_scev_Trunc(const Op0_t &Op0) {
return m_scev_Unary<SCEVTruncateExpr>(Op0);
}
+/// Match Op0 with any number of integral casts peeled off, so that a value and
+/// any trunc/zext/sext of it match the same pattern.
+template <typename Op0_t> struct SCEVIgnoreCasts_match {
+ Op0_t Op0;
+
+ SCEVIgnoreCasts_match(Op0_t Op0) : Op0(Op0) {}
+
+ bool match(const SCEV *S) const {
+ while (const auto *C = dyn_cast<SCEVIntegralCastExpr>(S))
+ S = C->getOperand().getPointer();
+ return Op0.match(S);
+ }
----------------
artagnon wrote:
Yes, we call quite a few APIs that look like they would create zext(trunc(x)), but I think we fold them when actually constructing the zext:
```cpp
// zext(trunc(x)) --> zext(x) or x or trunc(x)
if (const SCEVTruncateExpr *ST = dyn_cast<SCEVTruncateExpr>(Op)) {
// It's possible the bits taken off by the truncate were all zero bits. If
// so, we should be able to simplify this further.
const SCEV *X = ST->getOperand();
ConstantRange CR = getUnsignedRange(X);
unsigned TruncBits = getTypeSizeInBits(ST->getType());
unsigned NewBits = getTypeSizeInBits(Ty);
if (CR.truncate(TruncBits).zeroExtend(NewBits).contains(
CR.zextOrTrunc(NewBits)))
return getTruncateOrZeroExtend(X, Ty, Depth);
}
```
https://github.com/llvm/llvm-project/pull/216036
More information about the llvm-commits
mailing list