Index: include/llvm/IR/Attributes.td =================================================================== --- include/llvm/IR/Attributes.td +++ include/llvm/IR/Attributes.td @@ -235,3 +235,4 @@ def : MergeRule<"adjustCallerSSPLevel">; def : MergeRule<"adjustCallerStackProbes">; def : MergeRule<"adjustCallerStackProbeSize">; +def : MergeRule<"adjustMinLegalVectorWidth">; Index: lib/IR/Attributes.cpp =================================================================== --- lib/IR/Attributes.cpp +++ lib/IR/Attributes.cpp @@ -1682,6 +1682,33 @@ } } +/// If the inlined function defines a min legal vector width, then ensure +/// the calling function has the same or larger min legal vector width. This +/// function is called after the inlining decision has been made so we have to +/// merge the attribute this way. Heuristics that would use +/// min-legal-vector-width to determine inline compatibility would need to be +/// handled as part of inline cost analysis. +static void +adjustMinLegalVectorWidth(Function &Caller, const Function &Callee) { + if (Callee.hasFnAttribute("min-legal-vector-width")) { + uint64_t CalleeVectorWidth; + Callee.getFnAttribute("min-legal-vector-width") + .getValueAsString() + .getAsInteger(0, CalleeVectorWidth); + if (Caller.hasFnAttribute("min-legal-vector-width")) { + uint64_t CallerVectorWidth; + Caller.getFnAttribute("min-legal-vector-width") + .getValueAsString() + .getAsInteger(0, CallerVectorWidth); + if (CallerVectorWidth < CalleeVectorWidth) { + Caller.addFnAttr(Callee.getFnAttribute("min-legal-vector-width")); + } + } else { + Caller.addFnAttr(Callee.getFnAttribute("min-legal-vector-width")); + } + } +} + #define GET_ATTR_COMPAT_FUNC #include "AttributesCompatFunc.inc" Index: test/Transforms/Inline/inline-min-legal-vector-width.ll =================================================================== --- /dev/null +++ test/Transforms/Inline/inline-min-legal-vector-width.ll @@ -0,0 +1,29 @@ +; RUN: opt %s -inline -S | FileCheck %s + +define internal void @innerSmall() "min-legal-vector-width"="128" { + ret void +} + +define internal void @innerLarge() "min-legal-vector-width"="512" { + ret void +} + +define void @outerNoAttribute() { + call void @innerLarge() + ret void +} + +define void @outerConflictingAttributeSmall() "min-legal-vector-width"="128" { + call void @innerLarge() + ret void +} + +define void @outerConflictingAttributeLarge() "min-legal-vector-width"="512" { + call void @innerSmall() + ret void +} + +; CHECK: define void @outerNoAttribute() #0 +; CHECK: define void @outerConflictingAttributeSmall() #0 +; CHECK: define void @outerConflictingAttributeLarge() #0 +; CHECK: attributes #0 = { "min-legal-vector-width"="512" }