diff options
Diffstat (limited to 'test/Transforms/PlaceSafepoints')
-rw-r--r-- | test/Transforms/PlaceSafepoints/basic.ll | 94 | ||||
-rw-r--r-- | test/Transforms/PlaceSafepoints/call-in-loop.ll | 31 | ||||
-rw-r--r-- | test/Transforms/PlaceSafepoints/finite-loops.ll | 80 | ||||
-rw-r--r-- | test/Transforms/PlaceSafepoints/invokes.ll | 110 | ||||
-rw-r--r-- | test/Transforms/PlaceSafepoints/split-backedge.ll | 46 |
5 files changed, 361 insertions, 0 deletions
diff --git a/test/Transforms/PlaceSafepoints/basic.ll b/test/Transforms/PlaceSafepoints/basic.ll new file mode 100644 index 0000000..ca63da4 --- /dev/null +++ b/test/Transforms/PlaceSafepoints/basic.ll @@ -0,0 +1,94 @@ +; RUN: opt %s -S -place-safepoints | FileCheck %s + + +; Do we insert a simple entry safepoint? +define void @test_entry() gc "statepoint-example" { +; CHECK-LABEL: @test_entry +entry: +; CHECK-LABEL: entry +; CHECK: statepoint + ret void +} + +; On a non-gc function, we should NOT get an entry safepoint +define void @test_negative() { +; CHECK-LABEL: @test_negative +entry: +; CHECK-NOT: statepoint + ret void +} + +; Do we insert a backedge safepoint in a statically +; infinite loop? +define void @test_backedge() gc "statepoint-example" { +; CHECK-LABEL: test_backedge +entry: +; CHECK-LABEL: entry +; This statepoint is technically not required, but we don't exploit that yet. +; CHECK: statepoint + br label %other + +; CHECK-LABEL: other +; CHECK: statepoint +other: + call void undef() + br label %other +} + +; Check that we remove an unreachable block rather than trying +; to insert a backedge safepoint +define void @test_unreachable() gc "statepoint-example" { +; CHECK-LABEL: test_unreachable +entry: +; CHECK-LABEL: entry +; CHECK: statepoint + ret void + +; CHECK-NOT: other +; CHECK-NOT: statepoint +other: + br label %other +} + +declare void @foo() + +; Do we turn a call into it's own statepoint +define void @test_simple_call() gc "statepoint-example" { +; CHECK-LABEL: test_simple_call +entry: + br label %other +other: +; CHECK-LABEL: other +; CHECK: statepoint +; CHECK-NOT: gc.result + call void @foo() + ret void +} + +declare zeroext i1 @i1_return_i1(i1) + +define i1 @test_call_with_result() gc "statepoint-example" { +; CHECK-LABEL: test_call_with_result +; This is checking that a statepoint_poll + statepoint + result is +; inserted for a function that takes 1 argument. +; CHECK: gc.statepoint.p0f_isVoidf +; CHECK: gc.statepoint.p0f_i1i1f +; CHECK: (i1 (i1)* @i1_return_i1, i32 1, i32 0, i1 false, i32 0) +; CHECK: %call12 = call i1 @llvm.experimental.gc.result.i1 +entry: + %call1 = tail call i1 (i1)* @i1_return_i1(i1 false) + ret i1 %call1 +} + +; This function is inlined when inserting a poll. To avoid recursive +; issues, make sure we don't place safepoints in it. +declare void @do_safepoint() +define void @gc.safepoint_poll() { +; CHECK-LABEL: gc.safepoint_poll +; CHECK-LABEL: entry +; CHECK-NEXT: do_safepoint +; CHECK-NEXT: ret void +entry: + call void @do_safepoint() + ret void +} diff --git a/test/Transforms/PlaceSafepoints/call-in-loop.ll b/test/Transforms/PlaceSafepoints/call-in-loop.ll new file mode 100644 index 0000000..a220fc9 --- /dev/null +++ b/test/Transforms/PlaceSafepoints/call-in-loop.ll @@ -0,0 +1,31 @@ +; If there's a call in the loop which dominates the backedge, we +; don't need a safepoint poll (since the callee must contain a +; poll test). +;; RUN: opt %s -place-safepoints -S | FileCheck %s + +declare void @foo() + +define void @test1() gc "statepoint-example" { +; CHECK-LABEL: test1 + +entry: +; CHECK-LABEL: entry +; CHECK: statepoint + br label %loop + +loop: +; CHECK-LABEL: loop +; CHECK: @llvm.experimental.gc.statepoint.p0f_isVoidf(void ()* @foo +; CHECK-NOT: statepoint + call void @foo() + br label %loop +} + +; 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 +} diff --git a/test/Transforms/PlaceSafepoints/finite-loops.ll b/test/Transforms/PlaceSafepoints/finite-loops.ll new file mode 100644 index 0000000..8b64d24 --- /dev/null +++ b/test/Transforms/PlaceSafepoints/finite-loops.ll @@ -0,0 +1,80 @@ +; Tests to ensure that we are not placing backedge safepoints in +; loops which are clearly finite. +;; RUN: opt %s -place-safepoints -S | FileCheck %s + + +; 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 + +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 + +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 + +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 +} + + +; 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 +} diff --git a/test/Transforms/PlaceSafepoints/invokes.ll b/test/Transforms/PlaceSafepoints/invokes.ll new file mode 100644 index 0000000..5fd5bea --- /dev/null +++ b/test/Transforms/PlaceSafepoints/invokes.ll @@ -0,0 +1,110 @@ +; RUN: opt %s -S -place-safepoints | FileCheck %s + +declare i64 addrspace(1)* @"some_call"(i64 addrspace(1)*) +declare i32 @"personality_function"() + +define i64 addrspace(1)* @test_basic(i64 addrspace(1)* %obj, i64 addrspace(1)* %obj1) gc "statepoint-example" { +; CHECK-LABEL: entry: +entry: + ; CHECK: invoke + ; CHECK: statepoint + ; CHECK: some_call + %ret_val = invoke i64 addrspace(1)* @"some_call"(i64 addrspace(1)* %obj) + to label %normal_return unwind label %exceptional_return + +; CHECK-LABEL: normal_return: +; CHECK: gc.result +; CHECK: ret i64 + +normal_return: + ret i64 addrspace(1)* %ret_val + +; CHECK-LABEL: exceptional_return: +; CHECK: landingpad +; CHECK: ret i64 + +exceptional_return: + %landing_pad4 = landingpad {i8*, i32} personality i32 ()* @"personality_function" + cleanup + ret i64 addrspace(1)* %obj1 +} + +define i64 addrspace(1)* @test_two_invokes(i64 addrspace(1)* %obj, i64 addrspace(1)* %obj1) gc "statepoint-example" { +; CHECK-LABEL: entry: +entry: + ; CHECK: invoke + ; CHECK: statepoint + ; CHECK: some_call + %ret_val1 = invoke i64 addrspace(1)* @"some_call"(i64 addrspace(1)* %obj) + to label %second_invoke unwind label %exceptional_return + +; CHECK-LABEL: second_invoke: +second_invoke: + ; CHECK: invoke + ; CHECK: statepoint + ; CHECK: some_call + %ret_val2 = invoke i64 addrspace(1)* @"some_call"(i64 addrspace(1)* %ret_val1) + to label %normal_return unwind label %exceptional_return + +; CHECK-LABEL: normal_return: +normal_return: + ; CHECK: gc.result + ; CHECK: ret i64 + ret i64 addrspace(1)* %ret_val2 + +; CHECK: exceptional_return: +; CHECK: ret i64 + +exceptional_return: + %landing_pad4 = landingpad {i8*, i32} personality i32 ()* @"personality_function" + cleanup + ret i64 addrspace(1)* %obj1 +} + +define i64 addrspace(1)* @test_phi_node(i1 %cond, i64 addrspace(1)* %obj) gc "statepoint-example" { +; CHECK-LABEL: entry: +entry: + br i1 %cond, label %left, label %right + +left: + %ret_val_left = invoke i64 addrspace(1)* @"some_call"(i64 addrspace(1)* %obj) + to label %merge unwind label %exceptional_return + +right: + %ret_val_right = invoke i64 addrspace(1)* @"some_call"(i64 addrspace(1)* %obj) + to label %merge unwind label %exceptional_return + +; CHECK-LABEL: merge1: +; CHECK: gc.result +; CHECK: br label %merge + +; CHECK-LABEL: merge3: +; CHECK: gc.result +; CHECK: br label %merge + +; CHECK-LABEL: merge: +; CHECK: phi +; CHECK: ret i64 addrspace(1)* %ret_val +merge: + %ret_val = phi i64 addrspace(1)* [%ret_val_left, %left], [%ret_val_right, %right] + ret i64 addrspace(1)* %ret_val + +; CHECK-LABEL: exceptional_return: +; CHECK: ret i64 addrspace(1)* + +exceptional_return: + %landing_pad4 = landingpad {i8*, i32} personality i32 ()* @"personality_function" + cleanup + ret i64 addrspace(1)* %obj +} + +declare void @do_safepoint() +define void @gc.safepoint_poll() { +; CHECK-LABEL: gc.safepoint_poll +; CHECK-LABEL: entry +; CHECK-NEXT: do_safepoint +; CHECK-NEXT: ret void +entry: + call void @do_safepoint() + ret void +} diff --git a/test/Transforms/PlaceSafepoints/split-backedge.ll b/test/Transforms/PlaceSafepoints/split-backedge.ll new file mode 100644 index 0000000..176b54f --- /dev/null +++ b/test/Transforms/PlaceSafepoints/split-backedge.ll @@ -0,0 +1,46 @@ +;; A very basic test to make sure that splitting the backedge keeps working +;; RUN: opt -place-safepoints -spp-split-backedge=1 -S %s | FileCheck %s + +define void @test(i32, i1 %cond) gc "statepoint-example" { +; CHECK-LABEL: @test +; CHECK-LABEL: loop.loop_crit_edge +; CHECK: gc.statepoint +; CHECK-NEXT: br label %loop +entry: + br label %loop + +loop: + br i1 %cond, label %loop, label %exit + +exit: + ret void +} + +; Test for the case where a single conditional branch jumps to two +; different loop header blocks. Since we're currently using LoopSimplfy +; this doesn't hit the interesting case, but once we remove that, we need +; to be sure this keeps working. +define void @test2(i32, i1 %cond) gc "statepoint-example" { +; CHECK-LABEL: @test2 +; CHECK-LABE: loop.loopexit.split +; CHECK: gc.statepoint +; CHECK-NEXT: br label %loop +; CHECK-LABEL: loop2.loop2_crit_edge +; CHECK: gc.statepoint +; CHECK-NEXT: br label %loop2 +entry: + br label %loop + +loop: + br label %loop2 + +loop2: + br i1 %cond, label %loop, label %loop2 +} + +declare void @do_safepoint() +define void @gc.safepoint_poll() { +entry: + call void @do_safepoint() + ret void +} |