1*9880d681SAndroid Build Coastguard Worker; Tests to ensure that we are not placing backedge safepoints in 2*9880d681SAndroid Build Coastguard Worker; loops which are clearly finite. 3*9880d681SAndroid Build Coastguard Worker;; RUN: opt < %s -place-safepoints -spp-counted-loop-trip-width=32 -S | FileCheck %s 4*9880d681SAndroid Build Coastguard Worker;; RUN: opt < %s -place-safepoints -spp-counted-loop-trip-width=64 -S | FileCheck %s -check-prefix=COUNTED-64 5*9880d681SAndroid Build Coastguard Worker 6*9880d681SAndroid Build Coastguard Worker 7*9880d681SAndroid Build Coastguard Worker; A simple counted loop with trivially known range 8*9880d681SAndroid Build Coastguard Workerdefine void @test1(i32) gc "statepoint-example" { 9*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: test1 10*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: entry 11*9880d681SAndroid Build Coastguard Worker; CHECK: call void @do_safepoint 12*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: loop 13*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: call void @do_safepoint 14*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: exit 15*9880d681SAndroid Build Coastguard Worker 16*9880d681SAndroid Build Coastguard Workerentry: 17*9880d681SAndroid Build Coastguard Worker br label %loop 18*9880d681SAndroid Build Coastguard Worker 19*9880d681SAndroid Build Coastguard Workerloop: 20*9880d681SAndroid Build Coastguard Worker %counter = phi i32 [ 0 , %entry ], [ %counter.inc , %loop ] 21*9880d681SAndroid Build Coastguard Worker %counter.inc = add i32 %counter, 1 22*9880d681SAndroid Build Coastguard Worker %counter.cmp = icmp slt i32 %counter.inc, 16 23*9880d681SAndroid Build Coastguard Worker br i1 %counter.cmp, label %loop, label %exit 24*9880d681SAndroid Build Coastguard Worker 25*9880d681SAndroid Build Coastguard Workerexit: 26*9880d681SAndroid Build Coastguard Worker ret void 27*9880d681SAndroid Build Coastguard Worker} 28*9880d681SAndroid Build Coastguard Worker 29*9880d681SAndroid Build Coastguard Worker; The same counted loop, but with an unknown early exit 30*9880d681SAndroid Build Coastguard Workerdefine void @test2(i32) gc "statepoint-example" { 31*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: test2 32*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: entry 33*9880d681SAndroid Build Coastguard Worker; CHECK: call void @do_safepoint 34*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: loop 35*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: call void @do_safepoint 36*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: exit 37*9880d681SAndroid Build Coastguard Worker 38*9880d681SAndroid Build Coastguard Workerentry: 39*9880d681SAndroid Build Coastguard Worker br label %loop 40*9880d681SAndroid Build Coastguard Worker 41*9880d681SAndroid Build Coastguard Workerloop: 42*9880d681SAndroid Build Coastguard Worker %counter = phi i32 [ 0 , %entry ], [ %counter.inc , %continue ] 43*9880d681SAndroid Build Coastguard Worker %counter.inc = add i32 %counter, 1 44*9880d681SAndroid Build Coastguard Worker %counter.cmp = icmp slt i32 %counter.inc, 16 45*9880d681SAndroid Build Coastguard Worker br i1 undef, label %continue, label %exit 46*9880d681SAndroid Build Coastguard Worker 47*9880d681SAndroid Build Coastguard Workercontinue: 48*9880d681SAndroid Build Coastguard Worker br i1 %counter.cmp, label %loop, label %exit 49*9880d681SAndroid Build Coastguard Worker 50*9880d681SAndroid Build Coastguard Workerexit: 51*9880d681SAndroid Build Coastguard Worker ret void 52*9880d681SAndroid Build Coastguard Worker} 53*9880d681SAndroid Build Coastguard Worker 54*9880d681SAndroid Build Coastguard Worker; The range is a 8 bit value and we can't overflow 55*9880d681SAndroid Build Coastguard Workerdefine void @test3(i8 %upper) gc "statepoint-example" { 56*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: test3 57*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: entry 58*9880d681SAndroid Build Coastguard Worker; CHECK: call void @do_safepoint 59*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: loop 60*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: call void @do_safepoint 61*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: exit 62*9880d681SAndroid Build Coastguard Worker 63*9880d681SAndroid Build Coastguard Workerentry: 64*9880d681SAndroid Build Coastguard Worker br label %loop 65*9880d681SAndroid Build Coastguard Worker 66*9880d681SAndroid Build Coastguard Workerloop: 67*9880d681SAndroid Build Coastguard Worker %counter = phi i8 [ 0 , %entry ], [ %counter.inc , %loop ] 68*9880d681SAndroid Build Coastguard Worker %counter.inc = add nsw i8 %counter, 1 69*9880d681SAndroid Build Coastguard Worker %counter.cmp = icmp slt i8 %counter.inc, %upper 70*9880d681SAndroid Build Coastguard Worker br i1 %counter.cmp, label %loop, label %exit 71*9880d681SAndroid Build Coastguard Worker 72*9880d681SAndroid Build Coastguard Workerexit: 73*9880d681SAndroid Build Coastguard Worker ret void 74*9880d681SAndroid Build Coastguard Worker} 75*9880d681SAndroid Build Coastguard Worker 76*9880d681SAndroid Build Coastguard Worker; The range is a 64 bit value 77*9880d681SAndroid Build Coastguard Workerdefine void @test4(i64 %upper) gc "statepoint-example" { 78*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: test4 79*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: entry 80*9880d681SAndroid Build Coastguard Worker; CHECK: call void @do_safepoint 81*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: loop 82*9880d681SAndroid Build Coastguard Worker; CHECK: call void @do_safepoint 83*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: exit 84*9880d681SAndroid Build Coastguard Worker 85*9880d681SAndroid Build Coastguard Worker; COUNTED-64-LABEL: test4 86*9880d681SAndroid Build Coastguard Worker; COUNTED-64-LABEL: entry 87*9880d681SAndroid Build Coastguard Worker; COUNTED-64: call void @do_safepoint 88*9880d681SAndroid Build Coastguard Worker; COUNTED-64-LABEL: loop 89*9880d681SAndroid Build Coastguard Worker; COUNTED-64-NOT: call void @do_safepoint 90*9880d681SAndroid Build Coastguard Worker; COUNTED-64-LABEL: exit 91*9880d681SAndroid Build Coastguard Worker 92*9880d681SAndroid Build Coastguard Workerentry: 93*9880d681SAndroid Build Coastguard Worker br label %loop 94*9880d681SAndroid Build Coastguard Worker 95*9880d681SAndroid Build Coastguard Workerloop: 96*9880d681SAndroid Build Coastguard Worker %counter = phi i64 [ 0 , %entry ], [ %counter.inc , %loop ] 97*9880d681SAndroid Build Coastguard Worker %counter.inc = add i64 %counter, 1 98*9880d681SAndroid Build Coastguard Worker %counter.cmp = icmp slt i64 %counter.inc, %upper 99*9880d681SAndroid Build Coastguard Worker br i1 %counter.cmp, label %loop, label %exit 100*9880d681SAndroid Build Coastguard Worker 101*9880d681SAndroid Build Coastguard Workerexit: 102*9880d681SAndroid Build Coastguard Worker ret void 103*9880d681SAndroid Build Coastguard Worker} 104*9880d681SAndroid Build Coastguard Worker 105*9880d681SAndroid Build Coastguard Worker; This loop can run infinitely (for %upper == INT64_MAX) so it needs a 106*9880d681SAndroid Build Coastguard Worker; safepoint. 107*9880d681SAndroid Build Coastguard Workerdefine void @test5(i64 %upper) gc "statepoint-example" { 108*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: test5 109*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: entry 110*9880d681SAndroid Build Coastguard Worker; CHECK: call void @do_safepoint 111*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: loop 112*9880d681SAndroid Build Coastguard Worker; CHECK: call void @do_safepoint 113*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: exit 114*9880d681SAndroid Build Coastguard Worker 115*9880d681SAndroid Build Coastguard Worker; COUNTED-64-LABEL: test5 116*9880d681SAndroid Build Coastguard Worker; COUNTED-64-LABEL: entry 117*9880d681SAndroid Build Coastguard Worker; COUNTED-64: call void @do_safepoint 118*9880d681SAndroid Build Coastguard Worker; COUNTED-64-LABEL: loop 119*9880d681SAndroid Build Coastguard Worker; COUNTED-64: call void @do_safepoint 120*9880d681SAndroid Build Coastguard Worker; COUNTED-64-LABEL: exit 121*9880d681SAndroid Build Coastguard Worker 122*9880d681SAndroid Build Coastguard Workerentry: 123*9880d681SAndroid Build Coastguard Worker br label %loop 124*9880d681SAndroid Build Coastguard Worker 125*9880d681SAndroid Build Coastguard Workerloop: 126*9880d681SAndroid Build Coastguard Worker %counter = phi i64 [ 0 , %entry ], [ %counter.inc , %loop ] 127*9880d681SAndroid Build Coastguard Worker %counter.inc = add i64 %counter, 1 128*9880d681SAndroid Build Coastguard Worker %counter.cmp = icmp sle i64 %counter.inc, %upper 129*9880d681SAndroid Build Coastguard Worker br i1 %counter.cmp, label %loop, label %exit 130*9880d681SAndroid Build Coastguard Worker 131*9880d681SAndroid Build Coastguard Workerexit: 132*9880d681SAndroid Build Coastguard Worker ret void 133*9880d681SAndroid Build Coastguard Worker} 134*9880d681SAndroid Build Coastguard Worker 135*9880d681SAndroid Build Coastguard Worker 136*9880d681SAndroid Build Coastguard Worker; This function is inlined when inserting a poll. 137*9880d681SAndroid Build Coastguard Workerdeclare void @do_safepoint() 138*9880d681SAndroid Build Coastguard Workerdefine void @gc.safepoint_poll() { 139*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: gc.safepoint_poll 140*9880d681SAndroid Build Coastguard Workerentry: 141*9880d681SAndroid Build Coastguard Worker call void @do_safepoint() 142*9880d681SAndroid Build Coastguard Worker ret void 143*9880d681SAndroid Build Coastguard Worker}