[llvm] [LoadStoreVectorizer] Support vectorization of mixed-type contiguous accesses (PR #177908)
Anshil Gandhi via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 14 10:53:31 PDT 2026
================
@@ -160,7 +155,67 @@ struct ChainElem {
ChainElem(Instruction *Inst, APInt OffsetFromLeader)
: Inst(std::move(Inst)), OffsetFromLeader(std::move(OffsetFromLeader)) {}
};
-using Chain = SmallVector<ChainElem, 1>;
+struct Chain : SmallVector<ChainElem, 1> {
+private:
+ Type *ElemTy = nullptr;
+
+public:
+ using SmallVector::SmallVector;
+
+ /// Return the GCD of the element sizes.
+ unsigned int computeGCDSize(const DataLayout &DL) const {
+ unsigned int GCDSize = 0;
+ for (const ChainElem &E : *this) {
+ Type *Ty = getLoadStoreType(E.Inst)->getScalarType();
+ unsigned Sz = DL.getTypeSizeInBits(Ty);
+ GCDSize = GCDSize == 0 ? Sz : std::gcd(GCDSize, Sz);
+ }
+ return GCDSize;
+ }
+
+ /// Gets the element type of the vector that the chain will load or store.
+ ///
+ /// The element type is determined by taking the GCD of the bitwidths of all
+ /// elements in the chain. Among types with this matching bitwidth, we prefer:
+ /// - A type that appears most frequently in the chain, to minimize casts.
+ /// - An integer type if the chain contains pointers, to avoid direct
+ /// pointer-to-floating-point conversions.
+ ///
+ /// \param C The chain of instructions to be vectorized.
+ /// \returns The chosen element type for the vectorized load or store.
+ Type *computeAndCacheElemTy(LLVMContext &Ctx, const DataLayout &DL) {
----------------
gandhi56 wrote:
Addressed in the latest revision.
https://github.com/llvm/llvm-project/pull/177908
More information about the llvm-commits
mailing list