Files
clang-p2996/llvm/test/CodeGen/X86/loop-rotate.ll
Guozhi Wei d2210af332 [MBP] Move a latch block with conditional exit and multi predecessors to top of loop
Current findBestLoopTop can find and move one kind of block to top, a latch block has one successor. Another common case is:

    * a latch block
    * it has two successors, one is loop header, another is exit
    * it has more than one predecessors

If it is below one of its predecessors P, only P can fall through to it, all other predecessors need a jump to it, and another conditional jump to loop header. If it is moved before loop header, all its predecessors jump to it, then fall through to loop header. So all its predecessors except P can reduce one taken branch.

Differential Revision: https://reviews.llvm.org/D43256

llvm-svn: 363471
2019-06-14 23:08:59 +00:00

121 lines
2.0 KiB
LLVM

; RUN: llc -mtriple=i686-linux < %s | FileCheck %s
; Don't rotate the loop if the number of fall through to exit is not larger
; than the number of fall through to header.
define void @no_rotate() {
; CHECK-LABEL: no_rotate
; CHECK: %entry
; CHECK: %header
; CHECK: %middle
; CHECK: %latch1
; CHECK: %latch2
; CHECK: %end
entry:
br label %header
header:
%val1 = call i1 @foo()
br i1 %val1, label %middle, label %end
middle:
%val2 = call i1 @foo()
br i1 %val2, label %latch1, label %end
latch1:
%val3 = call i1 @foo()
br i1 %val3, label %latch2, label %header
latch2:
%val4 = call i1 @foo()
br label %header
end:
ret void
}
define void @do_rotate() {
; CHECK-LABEL: do_rotate
; CHECK: %entry
; CHECK: %then
; CHECK: %else
; CHECK: %latch1
; CHECK: %latch2
; CHECK: %header
; CHECK: %end
entry:
%val0 = call i1 @foo()
br i1 %val0, label %then, label %else
then:
call void @a()
br label %header
else:
call void @b()
br label %header
header:
%val1 = call i1 @foo()
br i1 %val1, label %latch1, label %end
latch1:
%val3 = call i1 @foo()
br i1 %val3, label %latch2, label %header
latch2:
%val4 = call i1 @foo()
br label %header
end:
ret void
}
; The loop structure is same as in @no_rotate, but the loop header's predecessor
; doesn't fall through to it, so it should be rotated to get exit fall through.
define void @do_rotate2() {
; CHECK-LABEL: do_rotate2
; CHECK: %entry
; CHECK: %then
; CHECK: %middle
; CHECK: %latch1
; CHECK: %latch2
; CHECK: %header
; CHECK: %exit
entry:
%val0 = call i1 @foo()
br i1 %val0, label %then, label %header, !prof !1
then:
call void @a()
br label %end
header:
%val1 = call i1 @foo()
br i1 %val1, label %middle, label %exit
middle:
%val2 = call i1 @foo()
br i1 %val2, label %latch1, label %exit
latch1:
%val3 = call i1 @foo()
br i1 %val3, label %latch2, label %header
latch2:
%val4 = call i1 @foo()
br label %header
exit:
call void @b()
br label %end
end:
ret void
}
declare i1 @foo()
declare void @a()
declare void @b()
!1 = !{!"branch_weights", i32 10, i32 1}