[llvm] [SLP][modularisation][NFC] Move pointer/stride helpers to SLPMemoryUtils (PR #221786)

Madhur Amilkanthwar via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 8 06:26:52 PDT 2026


================
@@ -0,0 +1,168 @@
+//===- SLPMemoryUtils.cpp - SLP pointer/stride helpers --------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "SLPMemoryUtils.h"
+#include "SLPCompatibilityAnalysis.h"
+#include "SLPUtils.h"
+
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/Analysis/ScalarEvolution.h"
+#include "llvm/Analysis/ScalarEvolutionExpressions.h"
+#include "llvm/Analysis/ValueTracking.h"
+#include "llvm/IR/DataLayout.h"
+#include "llvm/IR/Instructions.h"
+
+#include <algorithm>
+#include <set>
+#include <utility>
+
+using namespace llvm;
+
+namespace llvm::slpvectorizer {
+
+bool arePointersCompatible(Value *Ptr1, Value *Ptr2,
+                           const TargetLibraryInfo &TLI, unsigned MaxDepth,
+                           bool CompareOpcodes) {
+  if (getUnderlyingObject(Ptr1, MaxDepth) !=
+      getUnderlyingObject(Ptr2, MaxDepth))
+    return false;
+  auto *GEP1 = dyn_cast<GetElementPtrInst>(Ptr1);
+  auto *GEP2 = dyn_cast<GetElementPtrInst>(Ptr2);
+  return (!GEP1 || GEP1->getNumOperands() == 2) &&
+         (!GEP2 || GEP2->getNumOperands() == 2) &&
+         (((!GEP1 || isConstant(GEP1->getOperand(1))) &&
+           (!GEP2 || isConstant(GEP2->getOperand(1)))) ||
+          !CompareOpcodes ||
+          (GEP1 && GEP2 &&
+           getSameOpcode({GEP1->getOperand(1), GEP2->getOperand(1)}, TLI)));
+}
+
+/// Calculates minimal alignment as a common alignment.
+template <typename T> Align computeCommonAlignment(ArrayRef<Value *> VL) {
+  Align CommonAlignment = cast<T>(VL.consume_front())->getAlign();
+  for (Value *V : VL)
+    CommonAlignment = std::min(CommonAlignment, cast<T>(V)->getAlign());
+  return CommonAlignment;
+}
+
+template Align computeCommonAlignment<LoadInst>(ArrayRef<Value *>);
+template Align computeCommonAlignment<StoreInst>(ArrayRef<Value *>);
+
+/// Checks if the provided list of pointers \p Pointers represents the strided
+/// pointers for type ElemTy. If they are not, nullptr is returned.
+/// Otherwise, SCEV* of the stride value is returned.
+/// If `PointerOps` can be rearanged into the following sequence:
+/// ```
+/// %x + c_0 * stride,
+/// %x + c_1 * stride,
+/// %x + c_2 * stride
+/// ...
+/// ```
+/// where each `c_i` is constant. The SCEV of the `stride` will be returned.
----------------
madhur13490 wrote:

done.

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


More information about the llvm-commits mailing list