[llvm] [LV] Teach LoopVectorizationLegality about struct vector calls (PR #119221)

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 7 14:12:31 PST 2025


================
@@ -52,3 +52,12 @@ bool llvm::isVectorizedStructTy(StructType *StructTy) {
     return Ty->isVectorTy() && cast<VectorType>(Ty)->getElementCount() == VF;
   });
 }
+
+/// Returns true if `StructTy` is an unpacked literal struct where all elements
+/// are scalars that can be used as vector element types.
+bool llvm::canVectorizeStructTy(StructType *StructTy) {
+  auto ElemTys = StructTy->elements();
+  if (ElemTys.empty() || !isUnpackedStructLiteral(StructTy))
+    return false;
+  return all_of(ElemTys, VectorType::isValidElementType);
----------------
fhahn wrote:


nit: checks could be combined in single return ```suggestion
    return !ElemTys.empty() && isUnpackedStructLiteral(StructTy) &&
         all_of(ElemTys, VectorType::isValidElementType);
```

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


More information about the llvm-commits mailing list