[clang] [llvm] [SROA] Canonicalize homogeneous structs to fixed vectors (opt-in, after memcpyopt) (PR #165159)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Thu May 14 06:52:01 PDT 2026


================
@@ -5086,6 +5089,67 @@ bool SROA::presplitLoadsAndStores(AllocaInst &AI, AllocaSlices &AS) {
   return true;
 }
 
+/// Try to canonicalize a homogeneous struct partition to a vector type.
+///
+/// We can do this if all the elements of the struct are the same and tightly
+/// packed. This can sometimes eliminate allocas because structs cannot get
+/// promoted to LLVM values, but vectors can.
+///
+/// We only apply this transformation when all users of the alloca are memory
+/// intrinsics. Otherwise, if there is a load or store of some other type to the
+/// partition, SROA would select that type.
+///
+/// Applying this transformation too early may hinder memcpyopt, which may
+/// generate better code when eliminating allocas. For example, see
+/// `struct-to-vector-fp-store-only-tail.ll`, which demonstrates that applying
+/// this before memcpyopt can initialize previously uninitialized memory when
+/// the alloca gets promoted to an SSA value. For another example, see
----------------
arsenm wrote:

Is this about uninitialized memory being undef, and not poison? I don't see how changing the type fundamentally changes what bytes are defined or not 

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


More information about the llvm-commits mailing list