[llvm] 49d66d9 - [AFDO] Merge function attributes after inlining

Kazu Hirata via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 9 16:47:29 PDT 2021


Author: Kazu Hirata
Date: 2021-07-09T16:47:12-07:00
New Revision: 49d66d9f9f495caeb17de823c72f1459be819d9a

URL: https://github.com/llvm/llvm-project/commit/49d66d9f9f495caeb17de823c72f1459be819d9a
DIFF: https://github.com/llvm/llvm-project/commit/49d66d9f9f495caeb17de823c72f1459be819d9a.diff

LOG: [AFDO] Merge function attributes after inlining

This patch teaches the sample profile loader to merge function
attributes after inlining functions.

Without this patch, the compiler could inline a function requiring the
512-bit vector width into its caller without merging function
attributes, triggering a failure during instruction selection.

Differential Revision: https://reviews.llvm.org/D105729

Added: 
    llvm/test/Transforms/SampleProfile/Inputs/merge-function-attributes.afdo
    llvm/test/Transforms/SampleProfile/merge-function-attributes.ll

Modified: 
    llvm/lib/Transforms/IPO/SampleProfile.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/IPO/SampleProfile.cpp b/llvm/lib/Transforms/IPO/SampleProfile.cpp
index fe1776a13ba5a..4471c1a0dd388 100644
--- a/llvm/lib/Transforms/IPO/SampleProfile.cpp
+++ b/llvm/lib/Transforms/IPO/SampleProfile.cpp
@@ -1176,6 +1176,10 @@ bool SampleProfileLoader::tryInlineCandidate(
   InlineFunctionInfo IFI(nullptr, GetAC);
   IFI.UpdateProfile = false;
   if (InlineFunction(CB, IFI).isSuccess()) {
+    // Merge the attributes based on the inlining.
+    AttributeFuncs::mergeAttributesForInlining(*BB->getParent(),
+                                               *CalledFunction);
+
     // The call to InlineFunction erases I, so we can't pass it here.
     emitInlinedInto(*ORE, DLoc, BB, *CalledFunction, *BB->getParent(), Cost,
                     true, CSINLINE_DEBUG);

diff  --git a/llvm/test/Transforms/SampleProfile/Inputs/merge-function-attributes.afdo b/llvm/test/Transforms/SampleProfile/Inputs/merge-function-attributes.afdo
new file mode 100644
index 0000000000000..8f5d8503a70f5
--- /dev/null
+++ b/llvm/test/Transforms/SampleProfile/Inputs/merge-function-attributes.afdo
@@ -0,0 +1,2 @@
+xxx:82695217:2232
+ 67: yyy:5566623

diff  --git a/llvm/test/Transforms/SampleProfile/merge-function-attributes.ll b/llvm/test/Transforms/SampleProfile/merge-function-attributes.ll
new file mode 100644
index 0000000000000..baf8704cea48e
--- /dev/null
+++ b/llvm/test/Transforms/SampleProfile/merge-function-attributes.ll
@@ -0,0 +1,38 @@
+; RUN: opt < %s -passes=sample-profile -sample-profile-file=%S/Inputs/merge-function-attributes.afdo -S | FileCheck %s
+
+target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-grtev4-linux-gnu"
+
+; Verify that yyy is inlined into xxx with the function attibutes properly merged.
+; CHECK:      define <8 x double> @xxx(){{.*}} #[[ATTRNO:[0-9]+]]
+; CHECK-NEXT: call <8 x double> @llvm.x86.avx512.mask.rndscale.pd.512
+define <8 x double> @xxx() #0 !dbg !5 {
+  %x = call <8 x double> @yyy(), !dbg !7
+  ret <8 x double> %x
+}
+
+define available_externally <8 x double> @yyy() #1 !dbg !8 {
+  %y = call <8 x double> @llvm.x86.avx512.mask.rndscale.pd.512(<8 x double> zeroinitializer, i32 9, <8 x double> zeroinitializer, i8 -1, i32 4)
+  ret <8 x double> %y
+}
+
+; Function Attrs: nounwind readnone
+declare <8 x double> @llvm.x86.avx512.mask.rndscale.pd.512(<8 x double>, i32 immarg, <8 x double>, i8, i32 immarg) #2
+
+; CHECK: attributes #[[ATTRNO]] = { "min-legal-vector-width"="512"
+attributes #0 = { "min-legal-vector-width"="128" "prefer-vector-width"="128" "target-features"="+avx512vl" "use-sample-profile" }
+attributes #1 = { "min-legal-vector-width"="512" "use-sample-profile" }
+attributes #2 = { nounwind readnone }
+
+!llvm.dbg.cu = !{!0, !3}
+!llvm.module.flags = !{!4}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang", isOptimized: true, runtimeVersion: 0, emissionKind: NoDebug, enums: !2, splitDebugInlining: false, debugInfoForProfiling: true, nameTableKind: None)
+!1 = !DIFile(filename: "test.cc", directory: "/proc/self/cwd")
+!2 = !{}
+!3 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang", isOptimized: true, runtimeVersion: 0, emissionKind: NoDebug, splitDebugInlining: false, debugInfoForProfiling: true, nameTableKind: None)
+!4 = !{i32 2, !"Debug Info Version", i32 3}
+!5 = distinct !DISubprogram(name: "xxx", linkageName: "xxx", scope: !1, file: !1, line: 11, type: !6, scopeLine: 14, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !2)
+!6 = !DISubroutineType(types: !2)
+!7 = !DILocation(line: 78, column: 10, scope: !5)
+!8 = distinct !DISubprogram(name: "yyy", linkageName: "yyy", scope: !1, file: !1, line: 270, type: !6, scopeLine: 273, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !3, retainedNodes: !2)


        


More information about the llvm-commits mailing list