[llvm] [SROA] Prefer legal integers for array partitions (PR #219135)
Yonah Goldberg via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 27 00:49:19 PDT 2026
https://github.com/YonahGoldberg created https://github.com/llvm/llvm-project/pull/219135
None
>From 41d06340845cc1e4b1ce748c9c5fc03b88126c97 Mon Sep 17 00:00:00 2001
From: Yonah Goldberg <ygoldberg at nvidia.com>
Date: Thu, 27 Aug 2026 07:24:08 +0000
Subject: [PATCH] [SROA] Prefer legal integers for array partitions
---
llvm/lib/Transforms/Scalar/SROA.cpp | 16 ++++++++++++----
1 file changed, 12 insertions(+), 4 deletions(-)
diff --git a/llvm/lib/Transforms/Scalar/SROA.cpp b/llvm/lib/Transforms/Scalar/SROA.cpp
index e4770154e2998..42ba255052628 100644
--- a/llvm/lib/Transforms/Scalar/SROA.cpp
+++ b/llvm/lib/Transforms/Scalar/SROA.cpp
@@ -4804,6 +4804,14 @@ static Type *getTypePartition(const DataLayout &DL, Type *Ty, uint64_t Offset,
return SubTy;
}
+static bool containsNonIntegralPointer(Type *Ty, const DataLayout &DL) {
+ if (auto *PtrTy = dyn_cast<PointerType>(Ty))
+ return DL.isNonIntegralPointerType(PtrTy);
+ return llvm::any_of(Ty->subtypes(), [&](Type *SubTy) {
+ return containsNonIntegralPointer(SubTy, DL);
+ });
+}
+
/// Pre-split loads and stores to simplify rewriting.
///
/// We want to break up the splittable load+store pairs as much as
@@ -5458,11 +5466,11 @@ selectPartitionType(Partition &P, const DataLayout &DL, AllocaInst &AI,
// type?
if (Type *TypePartitionTy = getTypePartition(DL, AI.getAllocatedType(),
P.beginOffset(), P.size())) {
- // If the partition is an integer array that can be spanned by a legal
- // integer type, prefer to represent it as a legal integer type because
- // it's more likely to be promotable.
+ // If the partition is an array without non-integral pointers that can be
+ // spanned by a legal integer type, prefer to represent it as a legal
+ // integer type because it's more likely to be promotable.
if (TypePartitionTy->isArrayTy() &&
- TypePartitionTy->getArrayElementType()->isIntegerTy() &&
+ !containsNonIntegralPointer(TypePartitionTy, DL) &&
DL.isLegalInteger(P.size() * 8))
TypePartitionTy = Type::getIntNTy(C, P.size() * 8);
// There was no common type used, so we prefer integer widening promotion.
More information about the llvm-commits
mailing list