1 ; RUN: opt -S -licm -licm-coldness-threshold=0 < %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-mssa(licm),loop-sink' \
4 ; RUN: | FileCheck %s --check-prefix=CHECK-SINK
5 ; RUN: opt -S -licm -licm-coldness-threshold=0 -verify-memoryssa < %s | FileCheck %s --check-prefix=CHECK-LICM
6 ; RUN: opt -S -licm -verify-memoryssa < %s | FileCheck %s --check-prefix=CHECK-BFI-LICM
8 ; Original source code:
10 ; int foo(int p, int x) {
11 ; for (int i = 0; i != x; i++)
12 ; if (__builtin_expect(i == p, 0)) {
18 ; Load of global value g should not be hoisted to preheader.
20 @g = global i32 0, align 4
22 define i32 @foo(i32, i32) #0 !prof !2 {
23 %3 = icmp eq i32 %1, 0
24 br i1 %3, label %._crit_edge, label %.lr.ph.preheader
29 ; CHECK-LICM: .lr.ph.preheader:
30 ; CHECK-LICM: load i32, i32* @g
31 ; CHECK-LICM: br label %.lr.ph
33 ; CHECK-BFI-LICM: .lr.ph.preheader:
34 ; CHECK-BFI-LICM-NOT: load i32, i32* @g
35 ; CHECK-BFI-LICM: br label %.lr.ph
38 %.03 = phi i32 [ %8, %.combine ], [ 0, %.lr.ph.preheader ]
39 %.012 = phi i32 [ %.1, %.combine ], [ %1, %.lr.ph.preheader ]
40 %4 = icmp eq i32 %.03, %0
41 br i1 %4, label %.then, label %.combine, !prof !1
44 %5 = load i32, i32* @g, align 4
45 %6 = add nsw i32 %5, %.012
46 %7 = mul nsw i32 %6, %5
50 ; CHECK-SINK: load i32, i32* @g
51 ; CHECK-SINK: br label %.combine
54 %.1 = phi i32 [ %7, %.then ], [ %.012, %.lr.ph ]
55 %8 = add nuw nsw i32 %.03, 1
56 %9 = icmp eq i32 %8, %.1
57 br i1 %9, label %._crit_edge.loopexit, label %.lr.ph
60 %.1.lcssa = phi i32 [ %.1, %.combine ]
64 %.01.lcssa = phi i32 [ 0, %2 ], [ %.1.lcssa, %._crit_edge.loopexit ]
68 !1 = !{!"branch_weights", i32 1, i32 2000}
69 !2 = !{!"function_entry_count", i64 1}