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