[llvm] [SROA] Canonicalize homogeneous structs into fixed vectors (PR #165159)
Yaxun Liu via llvm-commits
llvm-commits at lists.llvm.org
Fri Jan 9 08:53:29 PST 2026
================
@@ -5267,6 +5273,57 @@ AllocaInst *SROA::rewritePartition(AllocaInst &AI, AllocaSlices &AS,
if (VecTy)
SliceTy = VecTy;
+ // Canonicalize homogeneous, tightly-packed 2- or 4-field structs to
+ // a fixed-width vector type when the DataLayout proves bitwise identity.
+ // Do this BEFORE the alloca reuse fast-path so that we don't miss
+ // opportunities to vectorize memcpy on allocas whose SliceTy initially
+ // equals the allocated type.
+ if (SROAMaxStructToVectorBytes) {
----------------
yxsamliu wrote:
Done. Extracted the logic into a helper function `tryCanonicalizeStructToVector()`
with early returns. The call site is now just:
```
if (auto *STy = dyn_cast<StructType>(PartitionTy))
if (auto *VTy = tryCanonicalizeStructToVector(STy, DL, MaxStructToVectorSize))
PartitionTy = VTy;
```
https://github.com/llvm/llvm-project/pull/165159
More information about the llvm-commits
mailing list