reference, declarationdefinition
definition → references, declarations, derived classes, virtual overrides
reference to multiple definitions → definitions
unreferenced
    1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19
   20
   21
   22
   23
   24
   25
   26
   27
   28
   29
   30
   31
   32
   33
   34
   35
   36
   37
   38
   39
   40
   41
   42
   43
   44
   45
   46
   47
   48
   49
   50
   51
   52
   53
   54
   55
   56
   57
   58
   59
   60
   61
   62
   63
   64
   65
   66
   67
   68
   69
   70
   71
   72
   73
   74
   75
   76
   77
   78
   79
   80
   81
   82
   83
   84
   85
   86
   87
   88
   89
   90
   91
   92
   93
   94
   95
   96
   97
   98
   99
  100
  101
  102
  103
  104
  105
  106
  107
  108
  109
  110
  111
  112
  113
  114
  115
  116
  117
  118
  119
  120
  121
  122
  123
  124
  125
  126
  127
  128
  129
  130
  131
  132
  133
  134
  135
  136
  137
  138
  139
  140
  141
  142
  143
; 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: call void @do_safepoint
; CHECK-LABEL: loop
; CHECK-NOT: call void @do_safepoint
; 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: call void @do_safepoint
; CHECK-LABEL: loop
; CHECK-NOT: call void @do_safepoint
; 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: call void @do_safepoint
; CHECK-LABEL: loop
; CHECK-NOT: call void @do_safepoint
; 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: call void @do_safepoint
; CHECK-LABEL: loop
; CHECK: call void @do_safepoint
; CHECK-LABEL: exit

; COUNTED-64-LABEL: test4
; COUNTED-64-LABEL: entry
; COUNTED-64: call void @do_safepoint
; COUNTED-64-LABEL: loop
; COUNTED-64-NOT: call void @do_safepoint
; 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: call void @do_safepoint
; CHECK-LABEL: loop
; CHECK: call void @do_safepoint
; CHECK-LABEL: exit

; COUNTED-64-LABEL: test5
; COUNTED-64-LABEL: entry
; COUNTED-64: call void @do_safepoint
; COUNTED-64-LABEL: loop
; COUNTED-64: call void @do_safepoint
; 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
}