Skip to content

Commit e76d79a

Browse files
author
Vasileios Porpodas
committed
[InlineCost] Don't call collectEphemeralValues() if too many assumptions
CallAnalyzer::analyze() can take several hours to run if the function contains thousands of @llvm.assume() calls. The time is spent in collectEphemeralvalues(). This patch adds a check that will disables the collection of ephemeral values if there are more assumptions than a limit controlled by the `-inline-ephval-assumptions-limit` flag.
1 parent 32bcc9f commit e76d79a

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

llvm/lib/Analysis/InlineCost.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,12 @@ static cl::opt<bool> DisableGEPConstOperand(
173173
"disable-gep-const-evaluation", cl::Hidden, cl::init(false),
174174
cl::desc("Disables evaluation of GetElementPtr with constant operands"));
175175

176+
static cl::opt<unsigned> EphValAssumptionsSzLimit(
177+
"inline-ephval-assumptions-limit", cl::Hidden, cl::init(5000),
178+
cl::desc("Collection of ephemeral values can be very expensive "
179+
"compile-time wise, so don't collect them if the function "
180+
"contains more than this many assumptions"));
181+
176182
namespace llvm {
177183
std::optional<int> getStringFnAttrAsInt(const Attribute &Attr) {
178184
if (Attr.isValid()) {
@@ -2785,7 +2791,15 @@ InlineResult CallAnalyzer::analyze() {
27852791
// the ephemeral values multiple times (and they're completely determined by
27862792
// the callee, so this is purely duplicate work).
27872793
SmallPtrSet<const Value *, 32> EphValues;
2788-
CodeMetrics::collectEphemeralValues(&F, &GetAssumptionCache(F), EphValues);
2794+
auto &AC = GetAssumptionCache(F);
2795+
// Don't collect ephemeral values if we have too many assumptions because the
2796+
// collection can be very expensive. Note that this will increase the cost of
2797+
// the function, making it less likely to be inlined. But if the function
2798+
// contains thousands of assumptions, then the chances are that it's too large
2799+
// to inline anyway.
2800+
bool TooExpensive = AC.assumptions().size() > EphValAssumptionsSzLimit;
2801+
if (!TooExpensive)
2802+
CodeMetrics::collectEphemeralValues(&F, &AC, EphValues);
27892803

27902804
// The worklist of live basic blocks in the callee *after* inlining. We avoid
27912805
// adding basic blocks of the callee which can be proven to be dead for this

0 commit comments

Comments
 (0)