brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.9 KiB · ff974f9 Raw
88 lines · plain
1; Check that the loop body frequency is maintained when LoopPeel both:2; - Peels one unconditional iteration after the loop.3; - Does not add a guard to sometimes skip the remaining loop because it has4;   proven the original loop always executes at least two iterations, which5;   become the initial iteration and the peeled iteration.6 7; DEFINE: %{exitWeight} =8; DEFINE: %{loopWeight} =9; DEFINE: %{loopFreqOld} =10; DEFINE: %{loopFreqNew} =11 12; DEFINE: %{run} = \13; DEFINE:   cp %s %t.ll && chmod +w %t.ll && \14; DEFINE:   echo '!0 = !{!"branch_weights", i32 %{exitWeight}, ' \15; DEFINE:       'i32 %{loopWeight}}' >> %t.ll && \16; DEFINE:   opt -p "print<block-freq>,loop-unroll,print<block-freq>" \17; DEFINE:       -unroll-full-max-count=0 -S %t.ll 2>&1 | \18; DEFINE:     FileCheck -DLOOP_FREQ_OLD='%{loopFreqOld}' \19; DEFINE:         -DLOOP_FREQ_NEW='%{loopFreqNew}' %s20 21; Branch weights give the original loop 10 iterations.  We expect that22; loopFreqOld = loopFreqNew + 1.23; REDEFINE: %{exitWeight} = 124; REDEFINE: %{loopWeight} = 925; REDEFINE: %{loopFreqOld} = 10.026; REDEFINE: %{loopFreqNew} = 9.027; RUN: %{run}28 29; Branch weights give the original loop 2 iterations.  We expect that30; loopFreqOld = loopFreqNew + 1.31; REDEFINE: %{exitWeight} = 132; REDEFINE: %{loopWeight} = 133; REDEFINE: %{loopFreqOld} = 2.034; REDEFINE: %{loopFreqNew} = 1.035; RUN: %{run}36 37; Branch weights give the original loop 1 iteration, but LoopPeel proved it has38; at least 2.  There is no loop probability that produces a frequency below 1,39; so the original total frequency cannot be maintained.40; REDEFINE: %{exitWeight} = 141; REDEFINE: %{loopWeight} = 042; REDEFINE: %{loopFreqOld} = 1.043; REDEFINE: %{loopFreqNew} = 1.044; RUN: %{run}45 46; Branch weights say the original loop is infinite, maximizing the frequency,47; so LoopPeel does not try to decrement it.48; REDEFINE: %{exitWeight} = 049; REDEFINE: %{loopWeight} = 150; REDEFINE: %{loopFreqOld} = 2147483647.851; REDEFINE: %{loopFreqNew} = 2147483647.852; RUN: %{run}53 54; Everything other than loop should be 1.0 because it is reached once.55;56;      CHECK: block-frequency-info: test57; CHECK-NEXT: - entry: float = 1.0,58; CHECK-NEXT: - loop: float = [[LOOP_FREQ_OLD]],59; CHECK-NEXT: - exit: float = 1.0,60;61;      CHECK: block-frequency-info: test62; CHECK-NEXT: - entry: float = 1.0,63; CHECK-NEXT: - loop: float = [[LOOP_FREQ_NEW]],64; CHECK-NEXT: - exit.peel.begin: float = 1.0,65; CHECK-NEXT: - loop.peel: float = 1.0,66; CHECK-NEXT: - exit.peel.next: float = 1.0,67; CHECK-NEXT: - loop.peel.next: float = 1.0,68; CHECK-NEXT: - exit: float = 1.0,69 70declare void @f(i32)71 72define void @test() {73entry:74  br label %loop75 76loop:77  %i = phi i32 [ 0, %entry ], [ %inc, %loop ]78  %isLast = icmp eq i32 %i, 2079  %sel = select i1 %isLast, i32 1, i32 080  call void @f(i32 %sel)81  %inc = add i32 %i, 182  %isLast1 = icmp eq i32 %i, 2083  br i1 %isLast1, label %exit, label %loop, !prof !084 85exit:86  ret void87}88