[PATCH] D104810: [Inline] prevent inlining on noprofile mismatch

Nick Desaulniers via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 23 12:52:35 PDT 2021


nickdesaulniers created this revision.
Herald added subscribers: dexonsmith, jdoerfert.
nickdesaulniers requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Similar to
commit bc044a88ee3c <https://reviews.llvm.org/rGbc044a88ee3c16e4164740732a7adc91a29b24f5> ("[Inline] prevent inlining on stack protector mismatch")

The noprofile function attribute is meant to prevent compiler
instrumentation from being inserted into a function. Inlining may defeat
the developer's intent. If the caller and callee don't either BOTH have
the attribute or BOTH lack the attribute, suppress inline substitution.

This matches behavior being proposed in GCC:
https://gcc.gnu.org/pipermail/gcc-patches/2021-June/573511.html
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80223


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D104810

Files:
  llvm/include/llvm/IR/Attributes.td
  llvm/test/Transforms/Inline/inline_noprofile.ll


Index: llvm/test/Transforms/Inline/inline_noprofile.ll
===================================================================
--- /dev/null
+++ llvm/test/Transforms/Inline/inline_noprofile.ll
@@ -0,0 +1,41 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt -passes=inline %s -S -pass-remarks-missed=inline 2>&1 | FileCheck %s
+
+; Test that we don't inline when caller and callee don't have matching
+; noprofile fn attrs.
+
+; CHECK: foo not inlined into bar because it should never be inlined (cost=never): conflicting attributes
+; CHECK: bar not inlined into baz because it should never be inlined (cost=never): conflicting attributes
+
+define i32 @foo() {
+; CHECK-LABEL: @foo(
+; CHECK-NEXT:    ret i32 42
+;
+  ret i32 42
+}
+
+define i32 @bar() noprofile {
+; CHECK-LABEL: @bar(
+; CHECK-NEXT:    [[TMP1:%.*]] = call i32 @foo()
+; CHECK-NEXT:    ret i32 [[TMP1]]
+;
+  %1 = call i32 @foo()
+  ret i32 %1
+}
+
+define i32 @baz() {
+; CHECK-LABEL: @baz(
+; CHECK-NEXT:    [[TMP1:%.*]] = call i32 @bar()
+; CHECK-NEXT:    ret i32 [[TMP1]]
+;
+  %1 = call i32 @bar()
+  ret i32 %1
+}
+
+define i32 @quux() {
+; CHECK-LABEL: @quux(
+; CHECK-NEXT:    ret i32 42
+;
+  %1 = call i32 @foo()
+  ret i32 %1
+}
Index: llvm/include/llvm/IR/Attributes.td
===================================================================
--- llvm/include/llvm/IR/Attributes.td
+++ llvm/include/llvm/IR/Attributes.td
@@ -297,6 +297,7 @@
 def : CompatRule<"isEqual<SafeStackAttr>">;
 def : CompatRule<"isEqual<ShadowCallStackAttr>">;
 def : CompatRule<"isEqual<UseSampleProfileAttr>">;
+def : CompatRule<"isEqual<NoProfileAttr>">;
 
 class MergeRule<string F> {
   // The name of the function called to merge the attributes of the caller and


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D104810.354057.patch
Type: text/x-patch
Size: 1757 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210623/2f59a6d7/attachment.bin>


More information about the llvm-commits mailing list