[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
================
@@ -1075,6 +1082,88 @@ std::vector<Chain> Vectorizer::splitChainByAlignment(Chain &C) {
return Ret;
}
+namespace {
+
+/// Reinterpret \p V as \p NewTy when both have the same total size. LLVM uses
+/// \p bitcast as the opcode for "bytecast"—same-width casts involving \p bN or
+/// byte vectors—so pointers do not unnecessarily go through \p ptrtoint /
+/// \p inttoptr. Use \p CreateBitOrPointerCast when neither type is involved in
+/// that encoding or when integer-to-pointer (\p inttoptr) is required.
+Value *reinterpretToSameSizedType(IRBuilderBase &Builder, Value *V,
+ Type *NewTy) {
+ Type *VTy = V->getType();
+ if ((VTy->isByteOrByteVectorTy() &&
+ (NewTy->isPtrOrPtrVectorTy() || NewTy->isIntOrIntVectorTy() ||
+ NewTy->isFPOrFPVectorTy())) ||
+ (NewTy->isByteOrByteVectorTy() &&
+ (VTy->isPtrOrPtrVectorTy() || VTy->isIntOrIntVectorTy() ||
+ VTy->isFPOrFPVectorTy())))
+ return Builder.CreateBitCast(V, NewTy);
+ return Builder.CreateBitOrPointerCast(V, NewTy);
+}
+
+/// View \p V as a scalar integer \p iSrcBits wide, using \p bitcast to flatten
+/// vectors and to cross FP / byte / int representations without resizing.
+Value *flattenToScalarInt(IRBuilderBase &Builder, Value *V, unsigned SrcBits,
+ LLVMContext &Ctx) {
+ Type *VTy = V->getType();
+ auto *IntTy = Type::getIntNTy(Ctx, SrcBits);
+ if (VTy->isVectorTy())
+ return Builder.CreateBitCast(V, IntTy);
+ if (VTy->isIntegerTy())
+ return V;
+ if (VTy->isByteTy())
+ return Builder.CreateBitCast(V, IntTy);
+ if (VTy->isFloatingPointTy())
+ return Builder.CreateBitCast(V, IntTy);
+ assert(VTy->isPointerTy() && "Unexpected type when flattening to integer");
+ return Builder.CreatePtrToInt(V, IntTy);
+}
+
+} // namespace
+
+/// Reinterpret the memory bit pattern between normalized vector lane types
+/// (\p bN or \p iN for sub-byte chains) and original load/store types.
+///
+/// Pipeline: normalize \p <N x i1> lanes to \p b1, flatten to \p iSrcBits when
+/// widths differ (\p bitcast for "bags of bits"), \p zext/\p trunc to the
+/// destination width, then \p reinterpretToSameSizedType (bitcast-first for
+/// byte types).
+Value *Vectorizer::resizeAndBitcast(Value *V, Type *NewTy) {
+ Type *VTy = V->getType();
----------------
gandhi56 wrote:
I realized we could simply call `CreateBitPreservingCastChain` now. We no longer need any of the helper functions. :)
https://github.com/llvm/llvm-project/pull/177908
More information about the llvm-commits
mailing list