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 ; RUN: opt -S -licm -enable-mssa-loop-dependency=true -verify-memoryssa < %s | FileCheck %s --check-prefix=CHECK-LICM
7 ; Original source code:
9 ; int foo(int p, int x) {
10 ; for (int i = 0; i != x; i++)
11 ; if (__builtin_expect(i == p, 0)) {
17 ; Load of global value g should not be hoisted to preheader.
19 @g = global i32 0, align 4
21 define i32 @foo(i32, i32) #0 !prof !2 {
22 %3 = icmp eq i32 %1, 0
23 br i1 %3, label %._crit_edge, label %.lr.ph.preheader
28 ; CHECK-LICM: .lr.ph.preheader:
29 ; CHECK-LICM: load i32, i32* @g
30 ; CHECK-LICM: br label %.lr.ph
33 %.03 = phi i32 [ %8, %.combine ], [ 0, %.lr.ph.preheader ]
34 %.012 = phi i32 [ %.1, %.combine ], [ %1, %.lr.ph.preheader ]
35 %4 = icmp eq i32 %.03, %0
36 br i1 %4, label %.then, label %.combine, !prof !1
39 %5 = load i32, i32* @g, align 4
40 %6 = add nsw i32 %5, %.012
41 %7 = mul nsw i32 %6, %5
45 ; CHECK-SINK: load i32, i32* @g
46 ; CHECK-SINK: br label %.combine
49 %.1 = phi i32 [ %7, %.then ], [ %.012, %.lr.ph ]
50 %8 = add nuw nsw i32 %.03, 1
51 %9 = icmp eq i32 %8, %.1
52 br i1 %9, label %._crit_edge.loopexit, label %.lr.ph
55 %.1.lcssa = phi i32 [ %.1, %.combine ]
59 %.01.lcssa = phi i32 [ 0, %2 ], [ %.1.lcssa, %._crit_edge.loopexit ]
63 !1 = !{!"branch_weights", i32 1, i32 2000}
64 !2 = !{!"function_entry_count", i64 1}