-
Notifications
You must be signed in to change notification settings - Fork 15.5k
[DRAFT][SROA] Promote aggregates as integers if they only have intrinsic users #173117
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
@llvm/pr-subscribers-llvm-transforms Author: Yonah Goldberg (YonahGoldberg) ChangesFull diff: https://github.com/llvm/llvm-project/pull/173117.diff 1 Files Affected:
diff --git a/llvm/lib/Transforms/Scalar/SROA.cpp b/llvm/lib/Transforms/Scalar/SROA.cpp
index f2a85cc7af441..0673360abaef3 100644
--- a/llvm/lib/Transforms/Scalar/SROA.cpp
+++ b/llvm/lib/Transforms/Scalar/SROA.cpp
@@ -1523,12 +1523,14 @@ LLVM_DUMP_METHOD void AllocaSlices::dump() const { print(dbgs()); }
/// Walk the range of a partitioning looking for a common type to cover this
/// sequence of slices.
-static std::pair<Type *, IntegerType *>
+/// Returns: {CommonType, LargestIntegerType, OnlyIntrinsicUsers}
+static std::tuple<Type *, IntegerType *, bool>
findCommonType(AllocaSlices::const_iterator B, AllocaSlices::const_iterator E,
uint64_t EndOffset) {
Type *Ty = nullptr;
bool TyIsCommon = true;
IntegerType *ITy = nullptr;
+ bool OnlyIntrinsicUsers = true;
// Note that we need to look at *every* alloca slice's Use to ensure we
// always get consistent results regardless of the order of slices.
@@ -1536,6 +1538,8 @@ findCommonType(AllocaSlices::const_iterator B, AllocaSlices::const_iterator E,
Use *U = I->getUse();
if (isa<IntrinsicInst>(*U->getUser()))
continue;
+ // We found a non-intrinsic user
+ OnlyIntrinsicUsers = false;
if (I->beginOffset() != B->beginOffset() || I->endOffset() != EndOffset)
continue;
@@ -1569,7 +1573,7 @@ findCommonType(AllocaSlices::const_iterator B, AllocaSlices::const_iterator E,
Ty = UserTy;
}
- return {TyIsCommon ? Ty : nullptr, ITy};
+ return {TyIsCommon ? Ty : nullptr, ITy, OnlyIntrinsicUsers};
}
/// PHI instructions that use an alloca and are subsequently loaded can be
@@ -5257,7 +5261,7 @@ selectPartitionType(Partition &P, const DataLayout &DL, AllocaInst &AI,
// Check if there is a common type that all slices of the partition use that
// spans the partition.
- auto [CommonUseTy, LargestIntTy] =
+ auto [CommonUseTy, LargestIntTy, OnlyIntrinsicUsers] =
findCommonType(P.begin(), P.end(), P.endOffset());
if (CommonUseTy) {
TypeSize CommonUseSize = DL.getTypeAllocSize(CommonUseTy);
@@ -5295,6 +5299,15 @@ selectPartitionType(Partition &P, const DataLayout &DL, AllocaInst &AI,
isIntegerWideningViable(P, LargestIntTy, DL))
return {LargestIntTy, true, nullptr};
+ // If there are only intrinsic users of an aggregate type, try to
+ // represent as a legal integer type because we are probably just copying
+ // data around and the integer can be promoted.
+ if (OnlyIntrinsicUsers && DL.isLegalInteger(P.size() * 8) &&
+ TypePartitionTy->isAggregateType())
+ auto *IntNTy = Type::getIntNTy(*C, P.size() * 8);
+ return {IntNTy, isIntegerWideningViable(P, IntNTy, DL), nullptr};
+ }
+
// Fallback to TypePartitionTy and we probably won't promote.
return {TypePartitionTy, false, nullptr};
}
|
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
🪟 Windows x64 Test Results
Failed Tests(click on a test name to see its output) LLVMLLVM.CodeGen/NVPTX/lower-byval-args.llIf these failures are unrelated to your changes (for example tests are broken or flaky at HEAD), please open an issue at https://github.com/llvm/llvm-project/issues and add the |
🐧 Linux x64 Test Results
Failed Tests(click on a test name to see its output) LLVMLLVM.CodeGen/NVPTX/lower-byval-args.llIf these failures are unrelated to your changes (for example tests are broken or flaky at HEAD), please open an issue at https://github.com/llvm/llvm-project/issues and add the |
1fee5c1 to
944e69c
Compare
No description provided.