[PATCH] D49162: [Inliner] Teach inliner to merge 'min-legal-vector-width' function attribute

Craig Topper via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 10 17:08:58 PDT 2018


craig.topper created this revision.
craig.topper added a reviewer: chandlerc.
Herald added a subscriber: eraman.

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.

In the future we may want to have heuristics to block inlining for different vector widths possibly with another attribute, but we haven't defined that yet.

I've based this entirely on the stack-probe-size merging code.


https://reviews.llvm.org/D49162

Files:
  include/llvm/IR/Attributes.td
  lib/IR/Attributes.cpp
  test/Transforms/Inline/inline-min-legal-vector-width.ll


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" }
Index: lib/IR/Attributes.cpp
===================================================================
--- lib/IR/Attributes.cpp
+++ lib/IR/Attributes.cpp
@@ -1682,6 +1682,29 @@
   }
 }
 
+/// If the inlined function defines a min legal vector width, then ensure
+/// the calling function has the same or larger min legal vector width.
+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: 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">;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D49162.154904.patch
Type: text/x-patch
Size: 2544 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180711/cb9c6022/attachment-0001.bin>


More information about the llvm-commits mailing list