137 lines · plain
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py2; RUN: opt -S -passes=strip-gc-relocates,instcombine < %s | FileCheck %s3; test utility/debugging pass which removes gc.relocates, inserted by -rewrite-statepoints-for-gc4declare void @use_obj32(ptr addrspace(1)) "gc-leaf-function"5 6declare void @g()7declare token @llvm.experimental.gc.statepoint.p0(i64, i32, ptr, i32, i32, ...)8declare ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token, i32, i32) #09declare void @do_safepoint()10 11declare ptr addrspace(1) @new_instance() #112 13 14; Simple case: remove gc.relocate15define ptr addrspace(1) @test1(ptr addrspace(1) %arg) gc "statepoint-example" {16; CHECK-LABEL: @test1(17; CHECK-NEXT: entry:18; CHECK-NEXT: [[STATEPOINT_TOKEN:%.*]] = call token (i64, i32, ptr, i32, i32, ...) @llvm.experimental.gc.statepoint.p0(i64 2882400000, i32 0, ptr nonnull elementtype(void ()) @g, i32 0, i32 0, i32 0, i32 0) [ "deopt"(i32 100), "gc-live"() ]19; CHECK-NEXT: ret ptr addrspace(1) [[ARG:%.*]]20;21entry:22 %statepoint_token = call token (i64, i32, ptr, i32, i32, ...) @llvm.experimental.gc.statepoint.p0(i64 2882400000, i32 0, ptr elementtype(void ()) @g, i32 0, i32 0, i32 0, i32 0) ["gc-live"(ptr addrspace(1) %arg), "deopt" (i32 100)]23 %arg.relocated = call coldcc ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token %statepoint_token, i32 0, i32 0) ; (%arg, %arg)24 ret ptr addrspace(1) %arg.relocated25}26 27; Remove gc.relocates in presence of nested relocates.28define void @test2(ptr addrspace(1) %base) gc "statepoint-example" {29; CHECK-LABEL: @test2(30; CHECK-NEXT: entry:31; CHECK-NEXT: [[PTR_GEP1:%.*]] = getelementptr i8, ptr addrspace(1) [[BASE:%.*]], i64 12032; CHECK-NEXT: [[STATEPOINT_TOKEN:%.*]] = call token (i64, i32, ptr, i32, i32, ...) @llvm.experimental.gc.statepoint.p0(i64 2882400000, i32 0, ptr nonnull elementtype(void ()) @do_safepoint, i32 0, i32 0, i32 0, i32 0) [ "gc-live"() ]33; CHECK-NEXT: call void @use_obj32(ptr addrspace(1) [[PTR_GEP1]])34; CHECK-NEXT: [[STATEPOINT_TOKEN1:%.*]] = call token (i64, i32, ptr, i32, i32, ...) @llvm.experimental.gc.statepoint.p0(i64 2882400000, i32 0, ptr nonnull elementtype(void ()) @do_safepoint, i32 0, i32 0, i32 0, i32 0) [ "gc-live"() ]35; CHECK-NEXT: call void @use_obj32(ptr addrspace(1) [[PTR_GEP1]])36; CHECK-NEXT: ret void37;38entry:39 %ptr.gep = getelementptr i32, ptr addrspace(1) %base, i32 1540 %ptr.gep1 = getelementptr i32, ptr addrspace(1) %ptr.gep, i32 1541 %statepoint_token = call token (i64, i32, ptr, i32, i32, ...) @llvm.experimental.gc.statepoint.p0(i64 2882400000, i32 0, ptr elementtype(void ()) @do_safepoint, i32 0, i32 0, i32 0, i32 0) ["gc-live"(ptr addrspace(1) %ptr.gep1, ptr addrspace(1) %base)]42 %ptr.gep1.relocated = call coldcc ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token %statepoint_token, i32 1, i32 0) ; (%base, %ptr.gep1)43 %base.relocated = call coldcc ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token %statepoint_token, i32 1, i32 1) ; (%base, %base)44 call void @use_obj32(ptr addrspace(1) %ptr.gep1.relocated)45 %statepoint_token1 = call token (i64, i32, ptr, i32, i32, ...) @llvm.experimental.gc.statepoint.p0(i64 2882400000, i32 0, ptr elementtype(void ()) @do_safepoint, i32 0, i32 0, i32 0, i32 0) ["gc-live"(ptr addrspace(1) %ptr.gep1.relocated, ptr addrspace(1) %base.relocated)]46 %ptr.gep1.relocated2 = call coldcc ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token %statepoint_token1, i32 1, i32 0) ; (%base.relocated, %ptr.gep1.relocated)47 %base.relocated3 = call coldcc ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token %statepoint_token1, i32 1, i32 1) ; (%base.relocated, %base.relocated)48 call void @use_obj32(ptr addrspace(1) %ptr.gep1.relocated2)49 ret void50}51 52; landing pad gc.relocates removed by instcombine since it has no uses.53define ptr addrspace(1) @test3(ptr addrspace(1) %arg) gc "statepoint-example" personality i32 8 {54; CHECK-LABEL: @test3(55; CHECK-NEXT: entry:56; CHECK-NEXT: [[STATEPOINT_TOKEN:%.*]] = invoke token (i64, i32, ptr, i32, i32, ...) @llvm.experimental.gc.statepoint.p0(i64 2882400000, i32 0, ptr nonnull elementtype(void ()) @g, i32 0, i32 0, i32 0, i32 0) [ "deopt"(i32 100), "gc-live"() ]57; CHECK-NEXT: to label [[NORMAL_DEST:%.*]] unwind label [[UNWIND_DEST:%.*]]58; CHECK: normal_dest:59; CHECK-NEXT: ret ptr addrspace(1) [[ARG:%.*]]60; CHECK: unwind_dest:61; CHECK-NEXT: [[LPAD:%.*]] = landingpad token62; CHECK-NEXT: cleanup63; CHECK-NEXT: resume token undef64;65entry:66 %statepoint_token = invoke token (i64, i32, ptr, i32, i32, ...) @llvm.experimental.gc.statepoint.p0(i64 2882400000, i32 0, ptr elementtype(void ()) @g, i32 0, i32 0, i32 0, i32 0) ["gc-live"(ptr addrspace(1) %arg), "deopt" (i32 100)]67 to label %normal_dest unwind label %unwind_dest68 69normal_dest: ; preds = %entry70 %arg.relocated1 = call coldcc ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token %statepoint_token, i32 0, i32 0) ; (%arg, %arg)71 ret ptr addrspace(1) %arg.relocated172 73unwind_dest: ; preds = %entry74 %lpad = landingpad token75 cleanup76 %arg.relocated = call coldcc ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token %lpad, i32 0, i32 0) ; (%arg, %arg)77 resume token undef78}79 80; in presence of phi81define void @test4(i1 %cond) gc "statepoint-example" {82; CHECK-LABEL: @test4(83; CHECK-NEXT: entry:84; CHECK-NEXT: [[BASE1:%.*]] = call ptr addrspace(1) @new_instance()85; CHECK-NEXT: [[BASE2:%.*]] = call ptr addrspace(1) @new_instance()86; CHECK-NEXT: br i1 [[COND:%.*]], label [[HERE:%.*]], label [[THERE:%.*]]87; CHECK: here:88; CHECK-NEXT: br label [[MERGE:%.*]]89; CHECK: there:90; CHECK-NEXT: br label [[MERGE]]91; CHECK: merge:92; CHECK-NEXT: [[BASEPHI_BASE:%.*]] = phi ptr addrspace(1) [ [[BASE1]], [[HERE]] ], [ [[BASE2]], [[THERE]] ], !is_base_value !093; CHECK-NEXT: [[STATEPOINT_TOKEN:%.*]] = call token (i64, i32, ptr, i32, i32, ...) @llvm.experimental.gc.statepoint.p0(i64 2882400000, i32 0, ptr nonnull elementtype(void ()) @do_safepoint, i32 0, i32 0, i32 0, i32 0) [ "gc-live"() ]94; CHECK-NEXT: [[PTR_GEP_REMAT:%.*]] = getelementptr i8, ptr addrspace(1) [[BASEPHI_BASE]], i64 6095; CHECK-NEXT: call void @use_obj32(ptr addrspace(1) [[PTR_GEP_REMAT]])96; CHECK-NEXT: ret void97;98entry:99 %base1 = call ptr addrspace(1) @new_instance()100 %base2 = call ptr addrspace(1) @new_instance()101 br i1 %cond, label %here, label %there102 103here: ; preds = %entry104 br label %merge105 106there: ; preds = %entry107 br label %merge108 109merge: ; preds = %there, %here110 %basephi.base = phi ptr addrspace(1) [ %base1, %here ], [ %base2, %there ], !is_base_value !0111 %basephi = phi ptr addrspace(1) [ %base1, %here ], [ %base2, %there ]112 %ptr.gep = getelementptr i32, ptr addrspace(1) %basephi, i32 15113 %statepoint_token = call token (i64, i32, ptr, i32, i32, ...) @llvm.experimental.gc.statepoint.p0(i64 2882400000, i32 0, ptr elementtype(void ()) @do_safepoint, i32 0, i32 0, i32 0, i32 0) ["gc-live"(ptr addrspace(1) %basephi.base)]114 %basephi.base.relocated = call coldcc ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token %statepoint_token, i32 0, i32 0) ; (%basephi.base, %basephi.base)115 %ptr.gep.remat = getelementptr i32, ptr addrspace(1) %basephi.base.relocated, i32 15116 call void @use_obj32(ptr addrspace(1) %ptr.gep.remat)117 ret void118}119 120; The gc.relocate type is different from %arg, but removing the gc.relocate,121; needs a bitcast to be added from ptr addrspace(1) to ptr addrspace(1)122define ptr addrspace(1) @test5(ptr addrspace(1) %arg) gc "statepoint-example" {123; CHECK-LABEL: @test5(124; CHECK-NEXT: entry:125; CHECK-NEXT: [[STATEPOINT_TOKEN:%.*]] = call token (i64, i32, ptr, i32, i32, ...) @llvm.experimental.gc.statepoint.p0(i64 2882400000, i32 0, ptr nonnull elementtype(void ()) @g, i32 0, i32 0, i32 0, i32 0) [ "deopt"(i32 100), "gc-live"() ]126; CHECK-NEXT: ret ptr addrspace(1) [[ARG:%.*]]127;128entry:129 %statepoint_token = call token (i64, i32, ptr, i32, i32, ...) @llvm.experimental.gc.statepoint.p0(i64 2882400000, i32 0, ptr elementtype(void ()) @g, i32 0, i32 0, i32 0, i32 0) ["gc-live"(ptr addrspace(1) %arg), "deopt" (i32 100)]130 %arg.relocated = call coldcc ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token %statepoint_token, i32 0, i32 0) ; (%arg, %arg)131 ret ptr addrspace(1) %arg.relocated132}133 134attributes #0 = { nounwind readonly }135attributes #1 = { nounwind "gc-leaf-function" }136!0 = !{}137