• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1; RUN: opt -enable-new-pm=1 -sample-profile -licm -S -sample-profile-file='%S/Inputs/no-hoist-prof.prof' < %s | FileCheck %s --check-prefix=CHECK-BFI-LICM
2; RUN: opt -passes=licm -S < %s | FileCheck %s --check-prefix=CHECK-LICM
3
4; Original source code:
5;
6; int bar(int);
7; int foo(int iter, int explode) {
8;   int base = bar(explode);
9;   for (int i = 0; i != iter; ++i)
10;     if (i == explode)
11;       iter = (base * base) + bar(iter);
12;   return iter;
13; }
14
15; We need debug information in this .ll in order to leverage the pgo file, so:
16; .ll generated by running `clang++ -O3 -g -S -emit-llvm`, then:
17;   - move hoisted mul back into cold section
18;   - give labels names
19;   - reindex variables
20;   - remove metadata calls, attributes, module header
21;   - remove unnecessary metadata
22
23; CHECK-LICM: .l.check.preheader:{{.*}}
24; CHECK-LICM-NEXT: {{.*}} = mul {{.*}}
25; CHECK-LICM-NEXT: br{{.*}}
26
27; CHECK-BFI-LICM: .l.cold:{{.*}}
28; CHECK-BFI-LICM-NEXT: {{.*}} = mul {{.*}}
29
30define dso_local i32 @_Z3fooii(i32, i32) local_unnamed_addr #0 !dbg !7 {
31  %3 = tail call i32 @_Z3bari(i32 %1), !dbg !19
32  %4 = icmp eq i32 %0, 0, !dbg !22
33  br i1 %4, label %.l.ret, label %.l.check.preheader, !dbg !24
34
35.l.check.preheader:
36  br label %.l.check, !dbg !24
37
38.l.ret:
39  %5 = phi i32 [ 0, %2 ], [ %12, %.l.iterate ]
40  ret i32 %5, !dbg !25
41
42.l.check:
43  %6 = phi i32 [ 0, %.l.check.preheader ], [ %13, %.l.iterate ]
44  %7 = phi i32 [ %0, %.l.check.preheader ], [ %12, %.l.iterate ]
45  %8 = icmp eq i32 %6, %1, !dbg !26
46  br i1 %8, label %.l.cold, label %.l.iterate, !dbg !28
47
48.l.cold:
49  %9 = mul nsw i32 %3, %3
50  %10 = tail call i32 @_Z3bari(i32 %7), !dbg !29
51  %11 = add nsw i32 %10, %9, !dbg !30
52  br label %.l.iterate, !dbg !31
53
54.l.iterate:
55  %12 = phi i32 [ %11, %.l.cold ], [ %7, %.l.check ]
56  %13 = add nuw nsw i32 %6, 1, !dbg !32
57  %14 = icmp eq i32 %13, %12, !dbg !22
58  br i1 %14, label %.l.ret, label %.l.check, !dbg !24, !llvm.loop !33
59}
60
61attributes #0 = { "use-sample-profile" }
62
63declare dso_local i32 @_Z3bari(i32) local_unnamed_addr #1
64
65!llvm.module.flags = !{!4}
66
67!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang version 8.0.20181009 ", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, nameTableKind: None)
68!1 = !DIFile(filename: "foo.cpp", directory: "/tmp/gather_pgo")
69!4 = !{i32 2, !"Debug Info Version", i32 3}
70!7 = distinct !DISubprogram(name: "foo", linkageName: "_Z3fooii", scope: !1, file: !1, line: 2, type: !8, isLocal: false, isDefinition: true, scopeLine: 2, flags: DIFlagPrototyped, isOptimized: true, unit: !0)
71!8 = !DISubroutineType(types: !9)
72!9 = !{!10, !10, !10}
73!10 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
74!16 = distinct !DILexicalBlock(scope: !7, file: !1, line: 4, column: 3)
75!19 = !DILocation(line: 3, column: 14, scope: !7)
76!22 = !DILocation(line: 4, column: 21, scope: !23)
77!23 = distinct !DILexicalBlock(scope: !16, file: !1, line: 4, column: 3)
78!24 = !DILocation(line: 4, column: 3, scope: !16)
79!25 = !DILocation(line: 7, column: 3, scope: !7)
80!26 = !DILocation(line: 5, column: 11, scope: !27)
81!27 = distinct !DILexicalBlock(scope: !23, file: !1, line: 5, column: 9)
82!28 = !DILocation(line: 5, column: 9, scope: !23)
83!29 = !DILocation(line: 6, column: 30, scope: !27)
84!30 = !DILocation(line: 6, column: 28, scope: !27)
85!31 = !DILocation(line: 6, column: 7, scope: !27)
86!32 = !DILocation(line: 4, column: 30, scope: !23)
87!33 = distinct !{!33, !24, !34}
88!34 = !DILocation(line: 6, column: 38, scope: !16)
89