Index: llvm/lib/CodeGen/SplitKit.cpp =================================================================== --- llvm/lib/CodeGen/SplitKit.cpp +++ llvm/lib/CodeGen/SplitKit.cpp @@ -702,6 +702,23 @@ LLVM_DEBUG(dbgs() << ": not live\n"); return End; } + SlotIndex LSP = SA.getLastSplitPoint(&MBB); + if (LSP < Last) { + // It could be that the use after LSP is a def, and thus the ParentVNI + // just selected starts at that def. For this case to exist, the def + // must be part of a tied def/use pair (as otherwise we'd have split + // distinct live ranges into individual live intervals), and thus we + // can insert the def into the VNI of the use and the tied def/use + // pair can live in the resulting interval. + Last = LSP; + ParentVNI = Edit->getParent().getVNInfoAt(Last); + if (!ParentVNI) { + // undef use --> undef tied def + LLVM_DEBUG(dbgs() << ": tied use not live\n"); + return End; + } + } + LLVM_DEBUG(dbgs() << ": valno " << ParentVNI->id); VNInfo *VNI = defFromParent(OpenIdx, ParentVNI, Last, MBB, SA.getLastSplitPointIter(&MBB)); Index: llvm/test/CodeGen/X86/statepoint-invoke-ra2.ll =================================================================== --- /dev/null +++ llvm/test/CodeGen/X86/statepoint-invoke-ra2.ll @@ -0,0 +1,136 @@ +; REQUIRES: asserts +; RUN: llc -o - %s -max-registers-for-gc-values=15 -use-registers-for-gc-values-in-landing-pad=true -use-registers-for-deopt-values=true -verify-regalloc 2>&1 | FileCheck %s + +; CHECK-NOT: Bad Parent VNI + +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" +target triple = "x86_64-unknown-linux-gnu" + +@global = external global i8 addrspace(1)*, align 8 +@global.1 = external global i8 addrspace(1)*, align 8 + +define void @bar(i8 addrspace(1)* %arg) #0 gc "statepoint-example" personality i32* ()* @zot { +bb: + %tmp = inttoptr i64 undef to i8 addrspace(1)* + br label %bb1 + +bb1: ; preds = %bb64, %bb + %tmp2 = phi i8 addrspace(1)* [ %tmp, %bb ], [ undef, %bb64 ] + %tmp3 = call token (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 2, i32 5, void ()* nonnull @wibble, i32 0, i32 0, i32 0, i32 0) [ "deopt"(i32 0, i32 2, i32 0, i32 0, i32 0, i32 1, i32 0, i32 7, i8* null, i32 2, i32 1, i32 0, i32 0, i32 5, i32 0, i32 7, i8* null, i32 7, i8* null, i32 7, i8* null, i32 7, i8* null, i32 7, i8* null), "gc-live"(i8 addrspace(1)* %tmp2) ] + %tmp4 = call coldcc i8 addrspace(1)* @llvm.experimental.gc.relocate.p1i8(token %tmp3, i32 0, i32 0) ; (%tmp2, %tmp2) + %tmp5 = call token (i64, i32, void (i8 addrspace(1)*)*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidp1i8f(i64 2882400000, i32 0, void (i8 addrspace(1)*)* nonnull @barney, i32 1, i32 0, i8 addrspace(1)* undef, i32 0, i32 0) [ "deopt"(i32 0, i32 2, i32 0, i32 0, i32 0, i32 1, i32 0, i32 7, i8* null, i32 9, i32 1, i32 9, i32 0, i32 5, i32 1, i32 7, i8* null, i32 8, i32 2, i32 7, i8* null, i32 7, i8* null, i32 7, i8* null, i32 8, i32 2), "gc-live"(i8 addrspace(1)* undef, i8 addrspace(1)* %tmp4) ] + %tmp6 = call coldcc i8 addrspace(1)* @llvm.experimental.gc.relocate.p1i8(token %tmp5, i32 1, i32 1) ; (%tmp4, %tmp4) + %tmp7 = call token (i64, i32, i8 addrspace(1)* ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_p1i8f(i64 2, i32 5, i8 addrspace(1)* ()* nonnull @blam, i32 0, i32 0, i32 0, i32 0) [ "deopt"(i32 0, i32 2, i32 0, i32 0, i32 0, i32 1, i32 0, i32 7, i8* null, i32 10, i32 1, i32 9, i32 0, i32 5, i32 1, i32 7, i8* null, i32 8, i32 2, i32 7, i8* null, i32 7, i8* null, i32 7, i8* null, i32 8, i32 2), "gc-live"(i8 addrspace(1)* %tmp6, i8 addrspace(1)* undef) ] + %tmp8 = call align 8 "java-type-kid"="69" i8 addrspace(1)* @llvm.experimental.gc.result.p1i8(token %tmp7) + %tmp9 = call coldcc i8 addrspace(1)* @llvm.experimental.gc.relocate.p1i8(token %tmp7, i32 0, i32 0) ; (%tmp6, %tmp6) + br i1 undef, label %bb64, label %bb10 + +bb10: ; preds = %bb1 + %tmp11 = inttoptr i64 undef to i8 addrspace(1)* + %tmp12 = call i8 addrspace(1)* @wobble.3(i8 addrspace(1)* undef, i8 addrspace(1)* addrspace(1)* undef) + %tmp13 = select i1 false, i8 addrspace(1)* null, i8 addrspace(1)* %tmp12 + %tmp14 = extractvalue { i32, i1 } undef, 1 + br i1 %tmp14, label %bb17, label %bb15 + +bb15: ; preds = %bb10 + %tmp16 = call token (i64, i32, void (i8 addrspace(1)*)*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidp1i8f(i64 2882400000, i32 0, void (i8 addrspace(1)*)* nonnull @barney, i32 1, i32 0, i8 addrspace(1)* undef, i32 0, i32 0) [ "deopt"(i32 0, i32 2, i32 0, i32 0, i32 0, i32 1, i32 0, i32 7, i8* null, i32 2, i32 1, i32 71, i32 0, i32 5, i32 0, i32 0, i8 addrspace(1)* %tmp13, i32 7, i8* null, i32 7, i8* null, i32 7, i8* null, i32 7, i8* null, i32 2, i32 5, i32 1, i32 0, i32 2, i32 0, i32 0, i8 addrspace(1)* %tmp8, i32 7, i8* null, i32 1, i32 6, i32 0, i32 0, i32 1, i32 1, i32 0, i8 addrspace(1)* %tmp8, i32 8, i32 10), "gc-live"(i8 addrspace(1)* %tmp9, i8 addrspace(1)* %tmp13, i8 addrspace(1)* %tmp11, i8 addrspace(1)* undef, i8 addrspace(1)* %tmp8) ] + unreachable + +bb17: ; preds = %bb10 + %tmp18 = load atomic i32, i32 addrspace(1)* undef unordered, align 4 + %tmp19 = and i32 %tmp18, 33554431 + %tmp20 = invoke token (i64, i32, void (i32, i8 addrspace(1)*)*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidi32p1i8f(i64 1, i32 16, void (i32, i8 addrspace(1)*)* nonnull @spam, i32 2, i32 0, i32 %tmp19, i8 addrspace(1)* nonnull undef, i32 0, i32 0) [ "deopt"(i32 0, i32 2, i32 0, i32 0, i32 0, i32 1, i32 0, i32 7, i8* null, i32 2, i32 1, i32 71, i32 0, i32 5, i32 0, i32 0, i8 addrspace(1)* %tmp13, i32 7, i8* null, i32 7, i8* null, i32 7, i8* null, i32 7, i8* null, i32 8, i32 5, i32 12, i32 0, i32 2, i32 0, i32 0, i8 addrspace(1)* %tmp8, i32 7, i8* null), "gc-live"(i8 addrspace(1)* %tmp9, i8 addrspace(1)* %tmp13, i8 addrspace(1)* %tmp13, i8 addrspace(1)* %tmp11, i8 addrspace(1)* %tmp8, i8 addrspace(1)* undef) ] + to label %bb21 unwind label %bb59 + +bb21: ; preds = %bb17 + %tmp22 = call coldcc i8 addrspace(1)* @llvm.experimental.gc.relocate.p1i8(token %tmp20, i32 0, i32 0) ; (%tmp9, %tmp9) + %tmp23 = call coldcc i8 addrspace(1)* @llvm.experimental.gc.relocate.p1i8(token %tmp20, i32 1, i32 1) ; (%tmp13, %tmp13) + %tmp24 = call coldcc i8 addrspace(1)* @llvm.experimental.gc.relocate.p1i8(token %tmp20, i32 3, i32 3) ; (%tmp11, %tmp11) + %tmp25 = load atomic i8 addrspace(1)*, i8 addrspace(1)** @global unordered, align 8 + %tmp26 = ptrtoint i8 addrspace(1)* %tmp25 to i64 + %tmp27 = xor i64 %tmp26, -1 + %tmp28 = inttoptr i64 %tmp27 to i8 addrspace(1)* + %tmp29 = call token (i64, i32, void (i8 addrspace(1)*)*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidp1i8f(i64 2, i32 5, void (i8 addrspace(1)*)* nonnull @baz, i32 1, i32 0, i8 addrspace(1)* undef, i32 0, i32 0) [ "deopt"(i32 0, i32 2, i32 0, i32 0, i32 0, i32 1, i32 0, i32 7, i8* null, i32 10, i32 1, i32 83, i32 0, i32 5, i32 1, i32 0, i8 addrspace(1)* %tmp23, i32 7, i8* null, i32 8, i32 2, i32 7, i8* null, i32 7, i8* null, i32 8, i32 2), "gc-live"(i8 addrspace(1)* %tmp22, i8 addrspace(1)* %tmp23, i8 addrspace(1)* %tmp23, i8 addrspace(1)* %tmp24, i8 addrspace(1)* %tmp28) ] + %tmp30 = call coldcc i8 addrspace(1)* @llvm.experimental.gc.relocate.p1i8(token %tmp29, i32 1, i32 2) ; (%tmp23, %tmp23) + %tmp31 = call coldcc i8 addrspace(1)* @llvm.experimental.gc.relocate.p1i8(token %tmp29, i32 4, i32 4) ; (%tmp28, %tmp28) + %tmp45 = load atomic i8 addrspace(1)*, i8 addrspace(1)** @global.1 unordered, align 8 + %tmp49 = load i32, i32 addrspace(256)* inttoptr (i64 660 to i32 addrspace(256)*), align 4 + %tmp32 = icmp eq i8 addrspace(1)* %tmp30, null + br i1 %tmp32, label %bb64, label %bb33 + +bb33: ; preds = %bb33, %bb21 + %tmp34 = phi i8 addrspace(1)* [ %tmp57, %bb33 ], [ undef, %bb21 ] + %tmp35 = phi i64 [ %tmp37, %bb33 ], [ 0, %bb21 ] + %tmp36 = phi i8 addrspace(1)* [ undef, %bb33 ], [ %tmp30, %bb21 ] + %tmp37 = add nuw nsw i64 %tmp35, 1 + %tmp38 = load atomic i8 addrspace(1)*, i8 addrspace(1)* addrspace(1)* undef unordered, align 8 + %tmp39 = ptrtoint i8 addrspace(1)* %tmp38 to i64 + %tmp40 = xor i64 %tmp39, -1 + %tmp41 = inttoptr i64 %tmp40 to i8 addrspace(1)* + %tmp42 = select i1 false, i8 addrspace(1)* null, i8 addrspace(1)* %tmp41 + %tmp43 = icmp eq i8 addrspace(1)* %tmp42, %tmp36 + %tmp44 = select i1 %tmp43, i8 addrspace(1)* null, i8 addrspace(1)* %tmp42 + call void asm sideeffect "lock btsq $0,($1)", "r,r,~{cc},~{dirflag},~{fpsr},~{flags}"(i64 0, i64* undef) + %tmp46 = ptrtoint i8 addrspace(1)* %tmp45 to i64 + %tmp47 = xor i64 %tmp46, -1 + %tmp48 = inttoptr i64 %tmp47 to i8 addrspace(1)* + %tmp50 = or i32 %tmp49, 268435456 + %tmp51 = cmpxchg i32 addrspace(1)* undef, i32 undef, i32 %tmp50 acquire monotonic + call void @wobble(i8 addrspace(1)* nonnull %tmp48) + %tmp52 = load atomic i8 addrspace(1)*, i8 addrspace(1)** @global unordered, align 8 + %tmp53 = ptrtoint i8 addrspace(1)* %tmp52 to i64 + %tmp54 = xor i64 %tmp53, -1 + %tmp55 = inttoptr i64 %tmp54 to i8 addrspace(1)* + %tmp56 = call token (i64, i32, void (i8 addrspace(1)*)*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidp1i8f(i64 2, i32 5, void (i8 addrspace(1)*)* nonnull @baz, i32 1, i32 0, i8 addrspace(1)* %tmp55, i32 0, i32 0) [ "deopt"(i32 0, i32 2, i32 0, i32 0, i32 0, i32 1, i32 0, i32 7, i8* null, i32 10, i32 1, i32 83, i32 0, i32 5, i32 1, i32 0, i8 addrspace(1)* %tmp44, i32 7, i8* null, i32 8, i32 2, i32 7, i8* null, i32 7, i8* null, i32 8, i32 2), "gc-live"(i8 addrspace(1)* undef, i8 addrspace(1)* %tmp44, i8 addrspace(1)* %tmp44, i8 addrspace(1)* %tmp34, i8 addrspace(1)* undef) ] + %tmp57 = call coldcc i8 addrspace(1)* @llvm.experimental.gc.relocate.p1i8(token %tmp56, i32 3, i32 3) ; (%tmp34, %tmp34) + %tmp58 = icmp ult i64 %tmp35, 65536 + br label %bb33 + +bb59: ; preds = %bb17 + %tmp60 = landingpad token + cleanup + %tmp61 = call coldcc i8 addrspace(1)* @llvm.experimental.gc.relocate.p1i8(token %tmp60, i32 1, i32 2) ; (%tmp13, %tmp13) + %tmp62 = call coldcc i8 addrspace(1)* @llvm.experimental.gc.relocate.p1i8(token %tmp60, i32 4, i32 4) ; (%tmp8, %tmp8) + %tmp63 = call token (i64, i32, void (i32)*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidi32f(i64 2882400000, i32 0, void (i32)* bitcast (void (i64)* @barney.2 to void (i32)*), i32 1, i32 2, i32 -13, i32 0, i32 0) [ "deopt"(i32 0, i32 2, i32 0, i32 0, i32 0, i32 1, i32 0, i32 7, i8* null, i32 2, i32 1, i32 71, i32 0, i32 5, i32 0, i32 0, i8 addrspace(1)* %tmp61, i32 7, i8* null, i32 7, i8* null, i32 7, i8* null, i32 7, i8* null, i32 1, i32 5, i32 21, i32 0, i32 2, i32 0, i32 0, i8 addrspace(1)* %tmp62, i32 0, i8 addrspace(1)* undef), "gc-live"() ] + unreachable + +bb64: ; preds = %bb21, %bb1 + %tmp65 = or i32 undef, 268435456 + %tmp66 = cmpxchg i32 addrspace(1)* undef, i32 undef, i32 %tmp65 acquire monotonic + %tmp67 = call token (i64, i32, void (i8 addrspace(1)*)*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidp1i8f(i64 2, i32 5, void (i8 addrspace(1)*)* nonnull @baz, i32 1, i32 0, i8 addrspace(1)* undef, i32 0, i32 0) [ "deopt"(i32 0, i32 2, i32 0, i32 0, i32 0, i32 1, i32 0, i32 7, i8* null, i32 10, i32 1, i32 133, i32 0, i32 5, i32 1, i32 7, i8* null, i32 8, i32 2, i32 7, i8* null, i32 7, i8* null, i32 7, i8* null, i32 8, i32 2), "gc-live"(i8 addrspace(1)* undef, i8 addrspace(1)* undef) ] + br label %bb1 +} + +declare i32* @zot() + +declare void @wibble() gc "statepoint-example" + +declare i8 addrspace(1)* @blam() gc "statepoint-example" + +declare void @baz(i8 addrspace(1)*) gc "statepoint-example" + +declare void @spam(i32, i8 addrspace(1)*) + +declare void @wobble(i8 addrspace(1)*) + +declare void @barney(i8 addrspace(1)*) + +declare token @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 immarg, i32 immarg, void ()*, i32 immarg, i32 immarg, ...) + +; Function Attrs: nounwind readonly +declare i8 addrspace(1)* @llvm.experimental.gc.relocate.p1i8(token, i32 immarg, i32 immarg) + +declare token @llvm.experimental.gc.statepoint.p0f_isVoidp1i8f(i64 immarg, i32 immarg, void (i8 addrspace(1)*)*, i32 immarg, i32 immarg, ...) + +declare token @llvm.experimental.gc.statepoint.p0f_p1i8f(i64 immarg, i32 immarg, i8 addrspace(1)* ()*, i32 immarg, i32 immarg, ...) + +; Function Attrs: nounwind readonly +declare i8 addrspace(1)* @llvm.experimental.gc.result.p1i8(token) + +declare token @llvm.experimental.gc.statepoint.p0f_isVoidi32p1i8f(i64 immarg, i32 immarg, void (i32, i8 addrspace(1)*)*, i32 immarg, i32 immarg, ...) + +declare void @barney.2(i64) + +declare token @llvm.experimental.gc.statepoint.p0f_isVoidi32f(i64 immarg, i32 immarg, void (i32)*, i32 immarg, i32 immarg, ...) + +declare i8 addrspace(1)* @wobble.3(i8 addrspace(1)*, i8 addrspace(1)* addrspace(1)*)