[llvm] [VectorCombine] Fold contiguous loads into a single vector load (PR #185736)

Simon Pilgrim via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 1 05:53:58 PDT 2026


================
@@ -6053,6 +6054,116 @@ bool VectorCombine::shrinkPhiOfShuffles(Instruction &I) {
   return true;
 }
 
+/// Check if a vector instruction's lanes originate from contiguous memory
+/// accesses. Fold the original loads and shuffles into a single vector load
+/// if it is profitable. For example:
+///     shufflevector(load <4 x float> ptr), poison, <2, 3>
+///       -> load <2 x float> (ptradd ptr, 8)
+/// Cost model calculations take into account the cost of the original
+/// unique load(s) and the target instruction versus the cost of the new
+/// aligned vector load.
+bool VectorCombine::foldContiguousLoads(Instruction &I) {
+  auto *VT = dyn_cast<FixedVectorType>(I.getType());
+  if (!VT || I.use_empty())
+    return false;
+
+  Type *EltTy = VT->getElementType();
+  if (!DL->typeSizeEqualsStoreSize(EltTy))
+    return false;
+
+  auto MaxInt64 = static_cast<uint64_t>(std::numeric_limits<int64_t>::max());
----------------
RKSimon wrote:

```suggestion
  uint64_t MaxInt64 = static_cast<uint64_t>(std::numeric_limits<int64_t>::max());
```

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


More information about the llvm-commits mailing list