[llvm] [SROA] Use tree-structure merge to remove alloca (PR #152793)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 19 15:00:07 PDT 2025
================
@@ -4981,13 +5273,20 @@ AllocaInst *SROA::rewritePartition(AllocaInst &AI, AllocaSlices &AS,
P.endOffset(), IsIntegerPromotable, VecTy,
PHIUsers, SelectUsers);
bool Promotable = true;
- for (Slice *S : P.splitSliceTails()) {
- Promotable &= Rewriter.visit(S);
- ++NumUses;
- }
- for (Slice &S : P) {
- Promotable &= Rewriter.visit(&S);
- ++NumUses;
+ // Check whether we can have tree-structured merge.
+ if (auto DeletedValues = Rewriter.rewriteTreeStructuredMerge(P)) {
+ NumUses += DeletedValues->size() + 1;
+ for (Value *V : *DeletedValues)
+ DeadInsts.push_back(V);
+ } else {
+ for (Slice *S : P.splitSliceTails()) {
+ Promotable &= Rewriter.visit(S);
+ ++NumUses;
+ }
+ for (Slice &S : P) {
+ Promotable &= Rewriter.visit(&S);
+ ++NumUses;
+ }
----------------
Chengjunp wrote:
I have verified that the impact of falling back to the old method is very small. Here is the result I had on the llvm compiler time tracker: https://llvm-compile-time-tracker.com/compare.php?from=f9cb95c9b0d52c11c7fbf11535cbd88039312ed3&to=74908e3a4491aa51b141a4d1de900c67b240cdc8&stat=instructions%3Au
https://github.com/llvm/llvm-project/pull/152793
More information about the llvm-commits
mailing list