[llvm] [InlineCost] Replace getAllocatedType with getAllocationSize (PR #178355)
Jameson Nash via llvm-commits
llvm-commits at lists.llvm.org
Thu Jan 29 07:46:54 PST 2026
https://github.com/vtjnash updated https://github.com/llvm/llvm-project/pull/178355
>From e517db9b3b1a08a2b7f026e02c25c321b29a384f Mon Sep 17 00:00:00 2001
From: Jameson Nash <vtjnash+github at gmail.com>
Date: Tue, 27 Jan 2026 16:05:33 +0000
Subject: [PATCH] [InlineCost] Replace getAllocatedType with getAllocationSize
This now correctly computes the size of the static alloca if it was
declared as an array.
Co-Authored-By: Claude Opus 4.5 <noreply at anthropic.com>
---
llvm/lib/Analysis/InlineCost.cpp | 23 ++++++++++++-----------
1 file changed, 12 insertions(+), 11 deletions(-)
diff --git a/llvm/lib/Analysis/InlineCost.cpp b/llvm/lib/Analysis/InlineCost.cpp
index 0e49b1903d410..710ea36ed2d2f 100644
--- a/llvm/lib/Analysis/InlineCost.cpp
+++ b/llvm/lib/Analysis/InlineCost.cpp
@@ -1602,19 +1602,20 @@ bool CallAnalyzer::visitAlloca(AllocaInst &I) {
}
}
- // Accumulate the allocated size.
if (I.isStaticAlloca()) {
- Type *Ty = I.getAllocatedType();
- AllocatedSize = SaturatingAdd(DL.getTypeAllocSize(Ty).getKnownMinValue(),
- AllocatedSize);
- }
-
- // FIXME: This is overly conservative. Dynamic allocas are inefficient for
- // a variety of reasons, and so we would like to not inline them into
- // functions which don't currently have a dynamic alloca. This simply
- // disables inlining altogether in the presence of a dynamic alloca.
- if (!I.isStaticAlloca())
+ // Accumulate the allocated size if constant and executed once.
+ // Note: if AllocSize is a vscale value, this is an underestimate of the
+ // allocated size, and it also requires some of the cost of a dynamic
+ // alloca, but is recorded here as a constant size alloca.
+ TypeSize AllocSize = I.getAllocationSize(DL).value_or(TypeSize::getZero());
+ AllocatedSize = SaturatingAdd(AllocSize.getKnownMinValue(), AllocatedSize);
+ } else {
+ // FIXME: This is overly conservative. Dynamic allocas are inefficient for
+ // a variety of reasons, and so we would like to not inline them into
+ // functions which don't currently have a dynamic alloca. This simply
+ // disables inlining altogether in the presence of a dynamic alloca.
HasDynamicAlloca = true;
+ }
return false;
}
More information about the llvm-commits
mailing list