1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -S -passes=rewrite-statepoints-for-gc < %s | FileCheck %s
4 target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128-ni:1-p2:32:8:8:32-ni:2"
5 target triple = "x86_64-unknown-linux-gnu"
7 declare void @foo() gc "statepoint-example"
8 declare i1 @runtime_value() "gc-leaf-function"
10 define ptr addrspace(1) @test1(ptr addrspace(1) %b1, ptr addrspace(1) %b2) gc "statepoint-example" {
11 ; CHECK-LABEL: @test1(
13 ; CHECK-NEXT: br label [[LOOP:%.*]]
15 ; CHECK-NEXT: [[B5:%.*]] = phi ptr addrspace(1) [ [[B1:%.*]], [[ENTRY:%.*]] ], [ [[B6:%.*]], [[INNER_LOOP_LATCH:%.*]] ]
16 ; CHECK-NEXT: [[C1:%.*]] = call i1 @runtime_value()
17 ; CHECK-NEXT: br i1 [[C1]], label [[INNER_LOOP:%.*]], label [[EXIT:%.*]]
19 ; CHECK-NEXT: [[B6]] = phi ptr addrspace(1) [ [[B5]], [[LOOP]] ], [ [[B6]], [[INNER_LOOP]] ]
20 ; CHECK-NEXT: [[C2:%.*]] = call i1 @runtime_value()
21 ; CHECK-NEXT: br i1 [[C2]], label [[INNER_LOOP]], label [[INNER_LOOP_LATCH]]
22 ; CHECK: inner_loop_latch:
23 ; CHECK-NEXT: [[C3:%.*]] = call i1 @runtime_value()
24 ; CHECK-NEXT: br i1 [[C3]], label [[LOOP]], label [[EXIT]]
26 ; CHECK-NEXT: [[MERGE:%.*]] = phi ptr addrspace(1) [ [[B5]], [[LOOP]] ], [ [[B6]], [[INNER_LOOP_LATCH]] ]
27 ; CHECK-NEXT: [[STATEPOINT_TOKEN:%.*]] = call token (i64, i32, ptr, i32, i32, ...) @llvm.experimental.gc.statepoint.p0(i64 2882400000, i32 0, ptr elementtype(void ()) @foo, i32 0, i32 0, i32 0, i32 0) [ "deopt"(), "gc-live"(ptr addrspace(1) [[MERGE]], ptr addrspace(1) [[B1]]) ]
28 ; CHECK-NEXT: [[MERGE_RELOCATED:%.*]] = call coldcc ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token [[STATEPOINT_TOKEN]], i32 1, i32 0)
29 ; CHECK-NEXT: [[B1_RELOCATED:%.*]] = call coldcc ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token [[STATEPOINT_TOKEN]], i32 1, i32 1)
30 ; CHECK-NEXT: ret ptr addrspace(1) [[MERGE_RELOCATED]]
36 %b5 = phi ptr addrspace(1) [ %b1, %entry ], [ %b6, %inner_loop_latch ]
37 %c1 = call i1 @runtime_value()
38 br i1 %c1, label %inner_loop, label %exit
41 %b6 = phi ptr addrspace(1) [ %b5, %loop ], [ %b6, %inner_loop ]
42 %c2 = call i1 @runtime_value()
43 br i1 %c2, label %inner_loop, label %inner_loop_latch
46 %c3 = call i1 @runtime_value()
47 br i1 %c3, label %loop, label %exit
50 %merge = phi ptr addrspace(1) [ %b5, %loop ], [ %b6, %inner_loop_latch ]
51 call void @foo() [ "deopt"() ]
52 ret ptr addrspace(1) %merge
55 define ptr addrspace(1) @swap(ptr addrspace(1) %b1, ptr addrspace(1) %b2) gc "statepoint-example" {
58 ; CHECK-NEXT: br label [[LOOP:%.*]]
60 ; CHECK-NEXT: [[B5:%.*]] = phi ptr addrspace(1) [ [[B1:%.*]], [[ENTRY:%.*]] ], [ [[B6:%.*]], [[LOOP]] ]
61 ; CHECK-NEXT: [[B6]] = phi ptr addrspace(1) [ [[B1]], [[ENTRY]] ], [ [[B5]], [[LOOP]] ]
62 ; CHECK-NEXT: [[C1:%.*]] = call i1 @runtime_value()
63 ; CHECK-NEXT: br i1 [[C1]], label [[LOOP]], label [[EXIT:%.*]]
65 ; CHECK-NEXT: [[STATEPOINT_TOKEN:%.*]] = call token (i64, i32, ptr, i32, i32, ...) @llvm.experimental.gc.statepoint.p0(i64 2882400000, i32 0, ptr elementtype(void ()) @foo, i32 0, i32 0, i32 0, i32 0) [ "deopt"(), "gc-live"(ptr addrspace(1) [[B6]], ptr addrspace(1) [[B1]]) ]
66 ; CHECK-NEXT: [[B6_RELOCATED:%.*]] = call coldcc ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token [[STATEPOINT_TOKEN]], i32 1, i32 0)
67 ; CHECK-NEXT: [[B1_RELOCATED:%.*]] = call coldcc ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token [[STATEPOINT_TOKEN]], i32 1, i32 1)
68 ; CHECK-NEXT: ret ptr addrspace(1) [[B6_RELOCATED]]
74 %b5 = phi ptr addrspace(1) [ %b1, %entry ], [ %b6, %loop ]
75 %b6 = phi ptr addrspace(1) [ %b1, %entry ], [ %b5, %loop ]
76 %c1 = call i1 @runtime_value()
77 br i1 %c1, label %loop, label %exit
80 call void @foo() [ "deopt"() ]
81 ret ptr addrspace(1) %b6