llvm/test/Transforms/PlaceSafepoints/finite-loops.ll
Bill Schmidt 9e24ab7252 [PowerPC] Add an MI SSA peephole pass.
This patch adds a pass for doing PowerPC peephole optimizations at the
MI level while the code is still in SSA form.  This allows for easy
modifications to the instructions while depending on a subsequent pass
of DCE.  Both passes are very fast due to the characteristics of SSA.

At this time, the only peepholes added are for cleaning up various
redundancies involving the XXPERMDI instruction.  However, I would
expect this will be a useful place to add more peepholes for
inefficiencies generated during instruction selection.  The pass is
placed after VSX swap optimization, as it is best to let that pass
remove unnecessary swaps before performing any remaining clean-ups.

The utility of these clean-ups are demonstrated by changes to four
existing test cases, all of which now have tighter expected code
generation.  I've also added Eric Schweiz's bugpoint-reduced test from
PR25157, for which we now generate tight code.  One other test started
failing for me, and I've fixed it
(test/Transforms/PlaceSafepoints/finite-loops.ll) as well; this is not
related to my changes, and I'm not sure why it works before and not
after.  The problem is that the CHECK-NOT: of "statepoint" from test1
fails because of the "statepoint" in test2, and so forth.  Adding a
CHECK-LABEL in between keeps the different occurrences of that string
properly scoped.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@252651 91177308-0d34-0410-b5e6-96231b3b80d8
2015-11-10 21:38:26 +00:00

143 lines
3.2 KiB
LLVM

; Tests to ensure that we are not placing backedge safepoints in
; loops which are clearly finite.
;; RUN: opt %s -place-safepoints -spp-counted-loop-trip-width=32 -S | FileCheck %s
;; RUN: opt %s -place-safepoints -spp-counted-loop-trip-width=64 -S | FileCheck %s -check-prefix=COUNTED-64
; A simple counted loop with trivially known range
define void @test1(i32) gc "statepoint-example" {
; CHECK-LABEL: test1
; CHECK-LABEL: entry
; CHECK: statepoint
; CHECK-LABEL: loop
; CHECK-NOT: statepoint
; CHECK-LABEL: exit
entry:
br label %loop
loop:
%counter = phi i32 [ 0 , %entry ], [ %counter.inc , %loop ]
%counter.inc = add i32 %counter, 1
%counter.cmp = icmp slt i32 %counter.inc, 16
br i1 %counter.cmp, label %loop, label %exit
exit:
ret void
}
; The same counted loop, but with an unknown early exit
define void @test2(i32) gc "statepoint-example" {
; CHECK-LABEL: test2
; CHECK-LABEL: entry
; CHECK: statepoint
; CHECK-LABEL: loop
; CHECK-NOT: statepoint
; CHECK-LABEL: exit
entry:
br label %loop
loop:
%counter = phi i32 [ 0 , %entry ], [ %counter.inc , %continue ]
%counter.inc = add i32 %counter, 1
%counter.cmp = icmp slt i32 %counter.inc, 16
br i1 undef, label %continue, label %exit
continue:
br i1 %counter.cmp, label %loop, label %exit
exit:
ret void
}
; The range is a 8 bit value and we can't overflow
define void @test3(i8 %upper) gc "statepoint-example" {
; CHECK-LABEL: test3
; CHECK-LABEL: entry
; CHECK: statepoint
; CHECK-LABEL: loop
; CHECK-NOT: statepoint
; CHECK-LABEL: exit
entry:
br label %loop
loop:
%counter = phi i8 [ 0 , %entry ], [ %counter.inc , %loop ]
%counter.inc = add nsw i8 %counter, 1
%counter.cmp = icmp slt i8 %counter.inc, %upper
br i1 %counter.cmp, label %loop, label %exit
exit:
ret void
}
; The range is a 64 bit value
define void @test4(i64 %upper) gc "statepoint-example" {
; CHECK-LABEL: test4
; CHECK-LABEL: entry
; CHECK: statepoint
; CHECK-LABEL: loop
; CHECK: statepoint
; CHECK-LABEL: exit
; COUNTED-64-LABEL: test4
; COUNTED-64-LABEL: entry
; COUNTED-64: statepoint
; COUNTED-64-LABEL: loop
; COUNTED-64-NOT: statepoint
; COUNTED-64-LABEL: exit
entry:
br label %loop
loop:
%counter = phi i64 [ 0 , %entry ], [ %counter.inc , %loop ]
%counter.inc = add i64 %counter, 1
%counter.cmp = icmp slt i64 %counter.inc, %upper
br i1 %counter.cmp, label %loop, label %exit
exit:
ret void
}
; This loop can run infinitely (for %upper == INT64_MAX) so it needs a
; safepoint.
define void @test5(i64 %upper) gc "statepoint-example" {
; CHECK-LABEL: test5
; CHECK-LABEL: entry
; CHECK: statepoint
; CHECK-LABEL: loop
; CHECK: statepoint
; CHECK-LABEL: exit
; COUNTED-64-LABEL: test5
; COUNTED-64-LABEL: entry
; COUNTED-64: statepoint
; COUNTED-64-LABEL: loop
; COUNTED-64: statepoint
; COUNTED-64-LABEL: exit
entry:
br label %loop
loop:
%counter = phi i64 [ 0 , %entry ], [ %counter.inc , %loop ]
%counter.inc = add i64 %counter, 1
%counter.cmp = icmp sle i64 %counter.inc, %upper
br i1 %counter.cmp, label %loop, label %exit
exit:
ret void
}
; This function is inlined when inserting a poll.
declare void @do_safepoint()
define void @gc.safepoint_poll() {
; CHECK-LABEL: gc.safepoint_poll
entry:
call void @do_safepoint()
ret void
}