[clang] [llvm] [SROA] Canonicalize homogeneous structs into fixed vectors (PR #165159)
Yaxun Liu via cfe-commits
cfe-commits at lists.llvm.org
Fri Apr 24 07:36:21 PDT 2026
================
@@ -5192,32 +5373,83 @@ selectPartitionType(Partition &P, const DataLayout &DL, AllocaInst &AI,
DL.isLegalInteger(P.size() * 8))
TypePartitionTy = Type::getIntNTy(C, P.size() * 8);
// There was no common type used, so we prefer integer widening promotion.
- if (isIntegerWideningViable(P, TypePartitionTy, DL))
+ if (isIntegerWideningViable(P, TypePartitionTy, DL)) {
+ LogChoice("type-partition-intwiden", TypePartitionTy, nullptr, true);
return {TypePartitionTy, true, nullptr};
- if (VecTy)
+ }
+ if (VecTy) {
+ LogChoice("type-partition-vecty", VecTy, VecTy, false);
return {VecTy, false, VecTy};
+ }
// If we couldn't promote with TypePartitionTy, try with the largest
// integer type used.
if (LargestIntTy &&
DL.getTypeAllocSize(LargestIntTy).getFixedValue() >= P.size() &&
- isIntegerWideningViable(P, LargestIntTy, DL))
+ isIntegerWideningViable(P, LargestIntTy, DL)) {
+ LogChoice("largest-int-intwiden", LargestIntTy, nullptr, true);
return {LargestIntTy, true, nullptr};
+ }
+
+ // Try homogeneous struct to vector canonicalization.
+ //
+ // This is intentionally more conservative than tryCanonicalize...
+ // alone: after the normal promotion paths above fail, we only want the
+ // struct-to-vector fallback when it can expose a real whole-value use,
+ // not when it would merely create vector lanes that later passes have to
+ // unpack again.
+ if (auto *STy = dyn_cast<StructType>(TypePartitionTy))
+ if (auto *VTy = tryCanonicalizeStructToVector(STy, DL)) {
+ // Recover only a narrow integer memcpy-only subset here. Broader
+ // fallback recovery was too aggressive:
+ // - full-record 16-byte { i64, i64 } cases reopened regressions
+ // - FP and lane-oriented cases were more likely to trigger bad later
+ // codegen
+ //
+ // So this path is restricted to 64-bit integer lanes, and only for
+ // interior partitions or original full records of size >= 32 bytes.
+ bool AllowStructFallback = shouldCanonicalizeHomogeneousStructToVector(
+ P, DL, AI, VTy->getElementType()->isIntegerTy(64));
+ LLVM_DEBUG({
----------------
yxsamliu wrote:
removed that extra debug-only block and now just rely on the main selection log
https://github.com/llvm/llvm-project/pull/165159
More information about the cfe-commits
mailing list