71 lines · plain
1; RUN: opt -passes="module(print<block-freq>),function(loop(loop-idiom)),module(print<block-freq>)" -mtriple=x86_64 -mcpu=core-avx2 %s -disable-output 2>&1 | FileCheck --check-prefix=PROFILE %s2 3declare void @escape_inner(i8, i8, i8, i1, i8)4declare void @escape_outer(i8, i8, i8, i1, i8)5 6declare i8 @gen.i8()7 8; Most basic pattern; Note that iff the shift amount is offset, said offsetting9; must not cause an overflow, but `add nsw` is fine.10define i8 @p0(i8 %val, i8 %start, i8 %extraoffset) mustprogress {11entry:12 br label %loop13 14loop:15 %iv = phi i8 [ %start, %entry ], [ %iv.next, %loop ]16 %nbits = add nsw i8 %iv, %extraoffset17 %val.shifted = ashr i8 %val, %nbits18 %val.shifted.iszero = icmp eq i8 %val.shifted, 019 %iv.next = add i8 %iv, 120 21 call void @escape_inner(i8 %iv, i8 %nbits, i8 %val.shifted, i1 %val.shifted.iszero, i8 %iv.next)22 23 br i1 %val.shifted.iszero, label %end, label %loop, !prof !{!"branch_weights", i32 1, i32 1000 }24 25end:26 %iv.res = phi i8 [ %iv, %loop ]27 %nbits.res = phi i8 [ %nbits, %loop ]28 %val.shifted.res = phi i8 [ %val.shifted, %loop ]29 %val.shifted.iszero.res = phi i1 [ %val.shifted.iszero, %loop ]30 %iv.next.res = phi i8 [ %iv.next, %loop ]31 32 call void @escape_outer(i8 %iv.res, i8 %nbits.res, i8 %val.shifted.res, i1 %val.shifted.iszero.res, i8 %iv.next.res)33 34 ret i8 %iv.res35}36 37define i32 @p1(i32 %x, i32 %bit) {38entry:39 %bitmask = shl i32 1, %bit40 br label %loop41 42loop:43 %x.curr = phi i32 [ %x, %entry ], [ %x.next, %loop ]44 %x.curr.bitmasked = and i32 %x.curr, %bitmask45 %x.curr.isbitunset = icmp eq i32 %x.curr.bitmasked, 046 %x.next = shl i32 %x.curr, 147 br i1 %x.curr.isbitunset, label %loop, label %end, !prof !{!"branch_weights", i32 500, i32 1 }48 49end:50 ret i32 %x.curr51}52 53;54; PROFILE: Printing analysis results of BFI for function 'p0':55; PROFILE: block-frequency-info: p056; PROFILE: - entry: float = 1.0,57; PROFILE: - loop: float = 1001.0,58; PROFILE: - end: float = 1.0,59; PROFILE: block-frequency-info: p160; PROFILE: - entry: float = 1.0, 61; PROFILE: - loop: float = 501.0,62; PROFILE: - end: float = 1.0,63; PROFILE: block-frequency-info: p064; PROFILE: - entry: float = 1.0,65; PROFILE: - loop: float = 1001.0,66; PROFILE: - end: float = 1.0,67; PROFILE: block-frequency-info: p168; PROFILE: - entry: float = 1.0, 69; PROFILE: - loop: float = 501.0,70; PROFILE: - end: float = 1.0,71