• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1; RUN: opt -S -licm < %s | FileCheck %s --check-prefix=CHECK-LICM
2; RUN: opt -S -licm < %s | opt -S -loop-sink | FileCheck %s --check-prefix=CHECK-SINK
3; RUN: opt -S < %s -passes='require<opt-remark-emit>,loop(licm),loop-sink' \
4; RUN:     | FileCheck %s --check-prefix=CHECK-SINK
5
6; Original source code:
7; int g;
8; int foo(int p, int x) {
9;   for (int i = 0; i != x; i++)
10;     if (__builtin_expect(i == p, 0)) {
11;       x += g; x *= g;
12;     }
13;   return x;
14; }
15;
16; Load of global value g should not be hoisted to preheader.
17
18@g = global i32 0, align 4
19
20define i32 @foo(i32, i32) #0 !prof !2 {
21  %3 = icmp eq i32 %1, 0
22  br i1 %3, label %._crit_edge, label %.lr.ph.preheader
23
24.lr.ph.preheader:
25  br label %.lr.ph
26
27; CHECK-LICM: .lr.ph.preheader:
28; CHECK-LICM: load i32, i32* @g
29; CHECK-LICM: br label %.lr.ph
30
31.lr.ph:
32  %.03 = phi i32 [ %8, %.combine ], [ 0, %.lr.ph.preheader ]
33  %.012 = phi i32 [ %.1, %.combine ], [ %1, %.lr.ph.preheader ]
34  %4 = icmp eq i32 %.03, %0
35  br i1 %4, label %.then, label %.combine, !prof !1
36
37.then:
38  %5 = load i32, i32* @g, align 4
39  %6 = add nsw i32 %5, %.012
40  %7 = mul nsw i32 %6, %5
41  br label %.combine
42
43; CHECK-SINK: .then:
44; CHECK-SINK: load i32, i32* @g
45; CHECK-SINK: br label %.combine
46
47.combine:
48  %.1 = phi i32 [ %7, %.then ], [ %.012, %.lr.ph ]
49  %8 = add nuw nsw i32 %.03, 1
50  %9 = icmp eq i32 %8, %.1
51  br i1 %9, label %._crit_edge.loopexit, label %.lr.ph
52
53._crit_edge.loopexit:
54  %.1.lcssa = phi i32 [ %.1, %.combine ]
55  br label %._crit_edge
56
57._crit_edge:
58  %.01.lcssa = phi i32 [ 0, %2 ], [ %.1.lcssa, %._crit_edge.loopexit ]
59  ret i32 %.01.lcssa
60}
61
62!1 = !{!"branch_weights", i32 1, i32 2000}
63!2 = !{!"function_entry_count", i64 1}
64