[llvm] [LSV] Support vectorization of mixed-type contiguous accesses (PR #177908)

Anshil Gandhi via llvm-commits llvm-commits at lists.llvm.org
Sat Jan 31 00:50:10 PST 2026


================
@@ -796,29 +793,38 @@ std::vector<Chain> Vectorizer::splitChainByContiguity(Chain &C) {
 
 Type *Vectorizer::getChainElemTy(const Chain &C) {
   assert(!C.empty());
-  // The rules are:
-  //  - If there are any pointer types in the chain, use an integer type.
-  //  - Prefer an integer type if it appears in the chain.
-  //  - Otherwise, use the first type in the chain.
-  //
-  // The rule about pointer types is a simplification when we merge e.g.  a load
-  // of a ptr and a double.  There's no direct conversion from a ptr to a
-  // double; it requires a ptrtoint followed by a bitcast.
-  //
-  // It's unclear to me if the other rules have any practical effect, but we do
-  // it to match this pass's previous behavior.
-  if (any_of(C, [](const ChainElem &E) {
-        return getLoadStoreType(E.Inst)->getScalarType()->isPointerTy();
-      })) {
-    return Type::getIntNTy(
-        F.getContext(),
-        DL.getTypeSizeInBits(getLoadStoreType(C[0].Inst)->getScalarType()));
+  unsigned GCDSize = 0;
+  SmallVector<Type *, 8> OriginalTypes;
+
+  for (const ChainElem &E : C) {
+    Type *Ty = getLoadStoreType(E.Inst)->getScalarType();
+    OriginalTypes.push_back(Ty);
+    unsigned Sz = DL.getTypeSizeInBits(Ty);
+    if (GCDSize == 0)
+      GCDSize = Sz;
+    else
+      GCDSize = std::gcd(GCDSize, Sz);
   }
 
-  for (const ChainElem &E : C)
-    if (Type *T = getLoadStoreType(E.Inst)->getScalarType(); T->isIntegerTy())
-      return T;
-  return getLoadStoreType(C[0].Inst)->getScalarType();
+  // Check if all types are floating point
+  if (std::all_of(OriginalTypes.begin(), OriginalTypes.end(),
+                  [](Type *Ty) { return Ty->isFloatingPointTy(); })) {
+    switch (GCDSize) {
+    case 16:
+      return Type::getHalfTy(F.getContext());
+    case 32:
+      return Type::getFloatTy(F.getContext());
+    case 64:
+      return Type::getDoubleTy(F.getContext());
+    }
+  }
----------------
gandhi56 wrote:

I will add cases for F80 and F128. I am not sure if there are plans to add more types. I will add a default case.

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


More information about the llvm-commits mailing list