Skip to content

Commit 1d504f7

Browse files
committed
[Inliner] Teach inliner to merge 'min-legal-vector-width' function attribute
When we inline a function with a min-legal-vector-width attribute we need to make sure the caller also ends up with at least that vector width. This patch is necessary to make always_inline functions like intrinsics propagate their min-legal-vector-width. Though nothing uses min-legal-vector-width yet. A future patch will add heuristics to preventing inlining with different vector width mismatches. But that code would need to be in inline cost analysis which is separate from the code added here. Differential Revision: https://reviews.llvm.org/D49162 llvm-svn: 337844
1 parent 1296c62 commit 1d504f7

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

llvm/include/llvm/IR/Attributes.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,3 +235,4 @@ def : MergeRule<"setOR<ProfileSampleAccurateAttr>">;
235235
def : MergeRule<"adjustCallerSSPLevel">;
236236
def : MergeRule<"adjustCallerStackProbes">;
237237
def : MergeRule<"adjustCallerStackProbeSize">;
238+
def : MergeRule<"adjustMinLegalVectorWidth">;

llvm/lib/IR/Attributes.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1682,6 +1682,33 @@ adjustCallerStackProbeSize(Function &Caller, const Function &Callee) {
16821682
}
16831683
}
16841684

1685+
/// If the inlined function defines a min legal vector width, then ensure
1686+
/// the calling function has the same or larger min legal vector width. This
1687+
/// function is called after the inlining decision has been made so we have to
1688+
/// merge the attribute this way. Heuristics that would use
1689+
/// min-legal-vector-width to determine inline compatibility would need to be
1690+
/// handled as part of inline cost analysis.
1691+
static void
1692+
adjustMinLegalVectorWidth(Function &Caller, const Function &Callee) {
1693+
if (Callee.hasFnAttribute("min-legal-vector-width")) {
1694+
uint64_t CalleeVectorWidth;
1695+
Callee.getFnAttribute("min-legal-vector-width")
1696+
.getValueAsString()
1697+
.getAsInteger(0, CalleeVectorWidth);
1698+
if (Caller.hasFnAttribute("min-legal-vector-width")) {
1699+
uint64_t CallerVectorWidth;
1700+
Caller.getFnAttribute("min-legal-vector-width")
1701+
.getValueAsString()
1702+
.getAsInteger(0, CallerVectorWidth);
1703+
if (CallerVectorWidth < CalleeVectorWidth) {
1704+
Caller.addFnAttr(Callee.getFnAttribute("min-legal-vector-width"));
1705+
}
1706+
} else {
1707+
Caller.addFnAttr(Callee.getFnAttribute("min-legal-vector-width"));
1708+
}
1709+
}
1710+
}
1711+
16851712
#define GET_ATTR_COMPAT_FUNC
16861713
#include "AttributesCompatFunc.inc"
16871714

0 commit comments

Comments
 (0)