[llvm-branch-commits] [llvm] [LoopVectorize] Support vectorization of compressing patterns (PR #214491)

Benjamin Maxwell via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Wed Sep 2 09:54:54 PDT 2026


================
@@ -2540,3 +2541,76 @@ llvm::hasPartialIVCondition(const Loop &L, unsigned MSSAThreshold,
 
   return {};
 }
+
+bool llvm::collectCompressedPtrs(
+    DenseMap<Value *, const SCEV *> &CompressedPtrs, const Loop &L,
+    const MonotonicDescriptor &MD, ScalarEvolution &SE) {
+  // Over-approximates the monotonic PHI as a SCEVAddRec assuming the condition
+  // is always true.
+  const SCEV *ApproximatePhiSCEV = SE.getAddRecExpr(
+      MD.getStartSCEV(), MD.getStepSCEV(), &L, SCEV::FlagAnyWrap);
+
+  // TODO: Take into account the non-wrap flags of the MD when rewriting the
+  // SCEV expressions for pointers. This should allow folding away zext/sext
+  // operations.
+  ValueToSCEVMapTy PhiMap{{MD.getHeaderPHI(), ApproximatePhiSCEV}};
+
+  auto GetCompressedPtrSCEV = [&](Value *Ptr, Type *AccessTy) -> const SCEV * {
+    const SCEV *PtrSCEV =
+        SCEVParameterRewriter::rewrite(SE.getSCEV(Ptr), SE, PhiMap);
+    auto *AddRec = dyn_cast<SCEVAddRecExpr>(PtrSCEV);
+    if (!AddRec || !AddRec->isAffine())
+      return nullptr;
+
+    // Check if pointer step equals access size.
+    SCEVUse Step = AddRec->getStepRecurrence(SE);
+    if (Step != SE.getSizeOfExpr(Step->getType(), AccessTy))
+      return nullptr;
+
+    return PtrSCEV;
+  };
+
+  SmallPtrSet<Use *, 16> Seen;
+  SmallVector<Use *> Worklist(make_pointer_range(MD.getHeaderPHI()->uses()));
----------------
MacDue wrote:

->users() returns a range of Use&, without `make_pointer_range()` it tries to copy the `Use` object into the worklist. 

https://github.com/llvm/llvm-project/pull/214491


More information about the llvm-branch-commits mailing list