Index: include/llvm/IR/CFGDeadness.h =================================================================== --- /dev/null +++ include/llvm/IR/CFGDeadness.h @@ -0,0 +1,104 @@ +//===- CFGDeadness.h - Dead Block and Edge Calculator -----------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file defines the CFGDeadness class, which provides deadness queries. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_IR_CFGDEADNESS_H +#define LLVM_IR_CFGDEADNESS_H + +#include "llvm/ADT/SetVector.h" +#include "llvm/IR/Dominators.h" +#include "llvm/IR/Instructions.h" + +namespace llvm { + +/// This CFG Deadness finds dead blocks and edges. Algorithm starts with a set +/// of blocks unreachable from entry then propagates deadness using foldable +/// conditional branches without modifying CFG. So GVN does but it changes CFG +/// by splitting critical edges. In most cases passes rely on SimplifyCFG to +/// clean up dead blocks, but in some cases, like verification or loop passes +/// it's not possible. +class CFGDeadness { + const DominatorTree *DT = nullptr; + SetVector DeadBlocks; + SetVector DeadEdges; // Contains all dead edges from live blocks. + +public: + /// Return the edge that coresponds to the predecessor. + static const Use& getEdge(const_pred_iterator &PredIt) { + auto &PU = PredIt.getUse(); + return PU.getUser()->getOperandUse(PU.getOperandNo()); + } + + /// Return true if there is at least one live edge that corresponds to the + /// basic block InBB listed in the phi node. + bool hasLiveIncomingEdge(const PHINode *PN, const BasicBlock *InBB) const; + + bool isDeadBlock(const BasicBlock *BB) const { + return DeadBlocks.count(BB); + } + + bool isDeadEdge(const Use *U) const { + assert(dyn_cast(U->getUser())->isTerminator() && + "edge must be operand of terminator"); + assert(cast_or_null(U->get()) && + "edge must refer to basic block"); + assert(!isDeadBlock(dyn_cast(U->getUser())->getParent()) && + "isDeadEdge() must be applied to edge from live block"); + return DeadEdges.count(U); + } + + bool hasLiveIncomingEdges(const BasicBlock *BB) const; + void processFunction(const Function &F, const DominatorTree &DT); + +protected: + void addDeadBlock(const BasicBlock *BB); + void addDeadEdge(const Use &DeadEdge); +}; + +/// Analysis pass which computes a \c CFGDeadness. +class CFGDeadnessAnalysis : public AnalysisInfoMixin { + friend AnalysisInfoMixin; + static AnalysisKey Key; + +public: + /// Provide the result typedef for this analysis pass. + using Result = CFGDeadness; + + /// Run the analysis pass over a function and produce a dominator tree. + CFGDeadness run(Function &F, FunctionAnalysisManager &FAM); +}; + +/// Legacy analysis pass which computes a \c CFGDeadness. +class CFGDeadnessWrapperPass : public FunctionPass { + CFGDeadness D; + +public: + static char ID; + + CFGDeadnessWrapperPass() : FunctionPass(ID) { + initializeCFGDeadnessWrapperPassPass(*PassRegistry::getPassRegistry()); + } + + CFGDeadness &getCFGDeadness() { return D; } + const CFGDeadness &getCFGDeadness() const { return D; } + + bool runOnFunction(Function &F) override; + + void getAnalysisUsage(AnalysisUsage &AU) const override { + AU.addRequiredID(DominatorTreeWrapperPass::ID); + AU.setPreservesAll(); + } +}; + +} // end namespace llvm + +#endif // LLVM_IR_CFGDEADNESS_H Index: include/llvm/InitializePasses.h =================================================================== --- include/llvm/InitializePasses.h +++ include/llvm/InitializePasses.h @@ -86,6 +86,7 @@ void initializeBreakCriticalEdgesPass(PassRegistry&); void initializeBreakFalseDepsPass(PassRegistry&); void initializeCallSiteSplittingLegacyPassPass(PassRegistry&); +void initializeCFGDeadnessWrapperPassPass(PassRegistry&); void initializeCFGOnlyPrinterLegacyPassPass(PassRegistry&); void initializeCFGOnlyViewerLegacyPassPass(PassRegistry&); void initializeCFGPrinterLegacyPassPass(PassRegistry&); Index: lib/IR/CFGDeadness.cpp =================================================================== --- /dev/null +++ lib/IR/CFGDeadness.cpp @@ -0,0 +1,165 @@ +//===- CFGDeadness.cpp - Dominator Calculation -----------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This CFG Deadness finds dead blocks and edges. Algorithm starts with a set +// of blocks unreachable from entry then propagates deadness using foldable +// conditional branches without modifying CFG. In most cases passes rely on +// SimplifyCFG to clean up such blocks, but in some cases, like verification +// or loop passes it's not possible. +// +//===----------------------------------------------------------------------===// + +#include "llvm/ADT/PostOrderIterator.h" +#include "llvm/IR/CFG.h" +#include "llvm/IR/CFGDeadness.h" +#include "llvm/IR/Constants.h" +#include "llvm/IR/Dominators.h" +#include "llvm/IR/Instructions.h" +#include "llvm/IR/PassManager.h" +#include "llvm/PassAnalysisSupport.h" +#include "llvm/Support/Debug.h" +#include +using namespace llvm; + +//===----------------------------------------------------------------------===// +// CFGDeadness Implementation +//===----------------------------------------------------------------------===// +// +// Provide public access to CFGDeadness information. Implementation details +// can be found in CFGDeadness.hpp. +// +//===----------------------------------------------------------------------===// + +bool CFGDeadness::hasLiveIncomingEdges(const BasicBlock *BB) const { + // Check if all incoming edges are dead. + for (const_pred_iterator PredIt(BB), End(BB, true); PredIt != End; ++PredIt) { + auto &PU = PredIt.getUse(); + const Use &U = PU.getUser()->getOperandUse(PU.getOperandNo()); + if (!isDeadBlock(*PredIt) && !isDeadEdge(&U)) + return true; // Found a live edge. + } + return false; +} + +void CFGDeadness::addDeadBlock(const BasicBlock *BB) { + SmallVector NewDead; + SmallSetVector DF; + + NewDead.push_back(BB); + while (!NewDead.empty()) { + const BasicBlock *D = NewDead.pop_back_val(); + if (isDeadBlock(D)) + continue; + + // All blocks dominated by D are dead. + SmallVector Dom; + DT->getDescendants(const_cast(D), Dom); + // Do not need to mark all in and out edges dead + // because BB is marked dead and this is enough + // to run further. + DeadBlocks.insert(Dom.begin(), Dom.end()); + + // Figure out the dominance-frontier(D). + for (BasicBlock *B : Dom) + for (BasicBlock *S : successors(B)) + if (!isDeadBlock(S) && !hasLiveIncomingEdges(S)) + NewDead.push_back(S); + } +} + +void CFGDeadness::addDeadEdge(const Use &DeadEdge) { + if (!DeadEdges.insert(&DeadEdge)) + return; + + BasicBlock *BB = cast_or_null(DeadEdge.get()); + if (hasLiveIncomingEdges(BB)) + return; + + addDeadBlock(BB); +} + +void CFGDeadness::processFunction(const Function &F, const DominatorTree &DT) { + this->DT = &DT; + + // Start with all blocks unreachable from entry. + for (const BasicBlock &BB : F) + if (!DT.isReachableFromEntry(&BB)) + DeadBlocks.insert(&BB); + + // Top-down walk of the dominator tree + ReversePostOrderTraversal RPOT(&F); + for (const BasicBlock *BB : RPOT) { + const TerminatorInst *TI = BB->getTerminator(); + assert(TI && "blocks must be well formed"); + + // For conditional branches, we can perform simple conditional propagation on + // the condition value itself. + const BranchInst *BI = dyn_cast(TI); + if (!BI || !BI->isConditional() || !isa(BI->getCondition())) + continue; + + // If a branch has two identical successors, we cannot declare either dead. + if (BI->getSuccessor(0) == BI->getSuccessor(1)) + continue; + + ConstantInt *Cond = dyn_cast(BI->getCondition()); + if (!Cond) + continue; + + addDeadEdge(BI->getOperandUse(Cond->getZExtValue() ? 1 : 2)); + } +} + +bool CFGDeadness::hasLiveIncomingEdge(const PHINode *PN, + const BasicBlock *InBB) const { + assert(!isDeadBlock(InBB) && "block must be live"); + const BasicBlock* BB = PN->getParent(); + bool Listed = false; + for (const_pred_iterator PredIt(BB), End(BB, true); PredIt != End; ++PredIt) { + if (InBB == *PredIt) { + if (!isDeadEdge(&getEdge(PredIt))) + return true; + Listed = true; + } + } + assert(Listed && "basic block is not found among incoming blocks"); + return false; +} + +//===----------------------------------------------------------------------===// +// CFGDeadnessAnalysis and related pass implementations +//===----------------------------------------------------------------------===// +// +// This implements the CFGDeadnessAnalysis which is used with the new pass +// manager. It also implements some methods from utility passes. +// +//===----------------------------------------------------------------------===// + +CFGDeadness CFGDeadnessAnalysis::run(Function &F, + FunctionAnalysisManager &AM) { +// auto &DT = getAnalysis().getDomTree(); + auto &DT = AM.getResult(F); + CFGDeadness D; + D.processFunction(F, DT); + return D; +} + +char CFGDeadnessWrapperPass::ID = 0; + +INITIALIZE_PASS_BEGIN(CFGDeadnessWrapperPass, "cfgdeadness", + "CFG Deadness", false, true) +INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass) +INITIALIZE_PASS_END(CFGDeadnessWrapperPass, "cfgdeadness", + "CFG Deadness", false, true) + +bool CFGDeadnessWrapperPass::runOnFunction(Function &F) { + auto &DT = getAnalysis().getDomTree(); + D.processFunction(F, DT); + return false; +} Index: lib/IR/CMakeLists.txt =================================================================== --- lib/IR/CMakeLists.txt +++ lib/IR/CMakeLists.txt @@ -7,6 +7,7 @@ Attributes.cpp AutoUpgrade.cpp BasicBlock.cpp + CFGDeadness.cpp Comdat.cpp ConstantFold.cpp ConstantRange.cpp Index: lib/IR/SafepointIRVerifier.cpp =================================================================== --- lib/IR/SafepointIRVerifier.cpp +++ lib/IR/SafepointIRVerifier.cpp @@ -36,6 +36,7 @@ #include "llvm/ADT/SetOperations.h" #include "llvm/ADT/SetVector.h" #include "llvm/IR/BasicBlock.h" +#include "llvm/IR/CFGDeadness.h" #include "llvm/IR/Dominators.h" #include "llvm/IR/Function.h" #include "llvm/IR/Instructions.h" @@ -59,23 +60,26 @@ static cl::opt PrintOnly("safepoint-ir-verifier-print-only", cl::init(false)); -static void Verify(const Function &F, const DominatorTree &DT); +static void Verify(const Function &F, const DominatorTree &DT, + const CFGDeadness &CD); namespace { struct SafepointIRVerifier : public FunctionPass { static char ID; // Pass identification, replacement for typeid - DominatorTree DT; SafepointIRVerifier() : FunctionPass(ID) { initializeSafepointIRVerifierPass(*PassRegistry::getPassRegistry()); } bool runOnFunction(Function &F) override { - DT.recalculate(F); - Verify(F, DT); + auto &DT = getAnalysis().getDomTree(); + auto &CD = getAnalysis().getCFGDeadness(); + Verify(F, DT, CD); return false; // no modifications } void getAnalysisUsage(AnalysisUsage &AU) const override { + AU.addRequiredID(DominatorTreeWrapperPass::ID); + AU.addRequiredID(CFGDeadnessWrapperPass::ID); AU.setPreservesAll(); } @@ -95,9 +99,11 @@ } INITIALIZE_PASS_BEGIN(SafepointIRVerifier, "verify-safepoint-ir", - "Safepoint IR Verifier", false, true) + "Safepoint IR Verifier", false, false) +INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass) +INITIALIZE_PASS_DEPENDENCY(CFGDeadnessWrapperPass) INITIALIZE_PASS_END(SafepointIRVerifier, "verify-safepoint-ir", - "Safepoint IR Verifier", false, true) + "Safepoint IR Verifier", false, false) static bool isGCPointerType(Type *T) { if (auto *PT = dyn_cast(T)) @@ -292,6 +298,7 @@ /// considered to be unrelocated and no false alarm will happen. class GCPtrTracker { const Function &F; + const CFGDeadness &CD; SpecificBumpPtrAllocator BSAllocator; DenseMap BlockMap; // This set contains defs of unrelocated pointers that are proved to be legal @@ -302,7 +309,12 @@ DenseSet PoisonedDefs; public: - GCPtrTracker(const Function &F, const DominatorTree &DT); + GCPtrTracker(const Function &F, const DominatorTree &DT, + const CFGDeadness &CD); + + bool hasLiveIncomingEdge(const PHINode *PN, const BasicBlock *InBB) const { + return CD.hasLiveIncomingEdge(PN, InBB); + } BasicBlockState *getBasicBlockState(const BasicBlock *BB); const BasicBlockState *getBasicBlockState(const BasicBlock *BB) const; @@ -318,8 +330,7 @@ static void verifyFunction(GCPtrTracker &&Tracker, InstructionVerifier &Verifier); - /// Returns true for reachable blocks that are verified, the other blocks are - /// ignored. + /// Returns true for reachable and live blocks. bool isMapped(const BasicBlock *BB) const { return BlockMap.find(BB) != BlockMap.end(); } @@ -378,10 +389,12 @@ }; } // end anonymous namespace -GCPtrTracker::GCPtrTracker(const Function &F, const DominatorTree &DT) : F(F) { - // First, calculate Contribution of each BB. +GCPtrTracker::GCPtrTracker(const Function &F, const DominatorTree &DT, + const CFGDeadness &CD) : F(F), CD(CD) { + // Calculate Contribution of each live BB. + // Allocate BB states for live blocks. for (const BasicBlock &BB : F) - if (DT.isReachableFromEntry(&BB)) { + if (!CD.isDeadBlock(&BB)) { BasicBlockState *BBS = new (BSAllocator.Allocate()) BasicBlockState; for (const auto &I : BB) transferInstruction(I, BBS->Cleared, BBS->Contribution); @@ -403,9 +416,7 @@ BasicBlockState *GCPtrTracker::getBasicBlockState(const BasicBlock *BB) { auto it = BlockMap.find(BB); - assert(it != BlockMap.end() && - "No such BB in BlockMap! Probably BB from another function"); - return it->second; + return it != BlockMap.end() ? it->second : nullptr; } const BasicBlockState *GCPtrTracker::getBasicBlockState( @@ -426,6 +437,9 @@ ReversePostOrderTraversal RPOT(&Tracker.F); for (const BasicBlock *BB : RPOT) { BasicBlockState *BBS = Tracker.getBasicBlockState(BB); + if (!BBS) + continue; + // We destructively modify AvailableIn as we traverse the block instruction // by instruction. AvailableValueSet &AvailableSet = BBS->AvailableIn; @@ -455,12 +469,17 @@ // The AvailableIn and AvailableOut sets decrease as we iterate. while (!Worklist.empty()) { const BasicBlock *BB = Worklist.pop_back_val(); - BasicBlockState *BBS = BlockMap[BB]; + BasicBlockState *BBS = getBasicBlockState(BB); + if (!BBS) + continue; // Ignore dead successors. size_t OldInCount = BBS->AvailableIn.size(); - for (const BasicBlock *PBB : predecessors(BB)) - if (isMapped(PBB)) - set_intersect(BBS->AvailableIn, BlockMap[PBB]->AvailableOut); + for (const_pred_iterator PredIt(BB), End(BB, true); PredIt != End; ++PredIt) { + const BasicBlock *PBB = *PredIt; + BasicBlockState *PBBS = getBasicBlockState(PBB); + if (PBBS && !CD.isDeadEdge(&CFGDeadness::getEdge(PredIt))) + set_intersect(BBS->AvailableIn, PBBS->AvailableOut); + } assert(OldInCount >= BBS->AvailableIn.size() && "invariant!"); @@ -499,8 +518,10 @@ bool HasUnrelocatedInputs = false; for (unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i) { const BasicBlock *InBB = PN->getIncomingBlock(i); - if (!isMapped(InBB)) - continue; + if (!isMapped(InBB) || + !CD.hasLiveIncomingEdge(PN, InBB)) + continue; // Skip dead block or dead edge. + const Value *InValue = PN->getIncomingValue(i); if (isNotExclusivelyConstantDerived(InValue)) { @@ -573,13 +594,15 @@ assert(DTN && "Unreachable blocks are ignored"); while (DTN->getIDom()) { DTN = DTN->getIDom(); - const auto &Defs = BlockMap[DTN->getBlock()]->Contribution; + auto BBS = getBasicBlockState(DTN->getBlock()); + assert(BBS && "immediate dominator cannot be dead for a live block"); + const auto &Defs = BBS->Contribution; Result.insert(Defs.begin(), Defs.end()); // If this block is 'Cleared', then nothing LiveIn to this block can be // available after this block completes. Note: This turns out to be // really important for reducing memory consuption of the initial available // sets and thus peak memory usage by this verifier. - if (BlockMap[DTN->getBlock()]->Cleared) + if (BBS->Cleared) return; } @@ -628,12 +651,15 @@ if (containsGCPtrType(PN->getType())) for (unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i) { const BasicBlock *InBB = PN->getIncomingBlock(i); - if (!Tracker->isMapped(InBB)) - continue; + const BasicBlockState *InBBS = Tracker->getBasicBlockState(InBB); + if (!InBBS || + !Tracker->hasLiveIncomingEdge(PN, InBB)) + continue; // Skip dead block or dead edge. + const Value *InValue = PN->getIncomingValue(i); if (isNotExclusivelyConstantDerived(InValue) && - !Tracker->getBasicBlockState(InBB)->AvailableOut.count(InValue)) + !InBBS->AvailableOut.count(InValue)) reportInvalidUse(*InValue, *PN); } } else if (isa(I) && @@ -710,13 +736,14 @@ AnyInvalidUses = true; } -static void Verify(const Function &F, const DominatorTree &DT) { +static void Verify(const Function &F, const DominatorTree &DT, + const CFGDeadness &CD) { LLVM_DEBUG(dbgs() << "Verifying gc pointers in function: " << F.getName() << "\n"); if (PrintOnly) dbgs() << "Verifying gc pointers in function: " << F.getName() << "\n"; - GCPtrTracker Tracker(F, DT); + GCPtrTracker Tracker(F, DT, CD); // We now have all the information we need to decide if the use of a heap // reference is legal or not, given our safepoint semantics. Index: test/SafepointIRVerifier/dead-block-tolerant.ll =================================================================== --- /dev/null +++ test/SafepointIRVerifier/dead-block-tolerant.ll @@ -0,0 +1,141 @@ +; RUN: opt -safepoint-ir-verifier-print-only -verify-safepoint-ir -S %s 2>&1 | FileCheck %s + +%jObject = type { [8 x i8] } +declare %jObject addrspace(1)* @llvm.experimental.gc.relocate.p1jObject(token, i32, i32) nounwind +declare token @llvm.experimental.gc.statepoint.p0f_f64f64f(i64, i32, double (double)*, i32, i32, ...) +declare token @llvm.experimental.gc.statepoint.p0f_isVoidf(i64, i32, void ()*, i32, i32, ...) + +; This test checks that dead branch (left) does not conflict with live branch (right). +define void @test2(i8 addrspace(1)* %arg, i1 %cond) gc "statepoint-example" { +; CHECK-LABEL: Verifying gc pointers in function: test2 +; CHECK: No illegal uses found by SafepointIRVerifier in: test2 + begin: + %ptr = getelementptr i8, i8 addrspace(1)* %arg, i64 4 + br i1 true, label %right, label %left + + left: + %safepoint_token = call token (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 0, i32 0, void ()* undef, i32 0, i32 0, i32 0, i32 5, i32 0, i32 -1, i32 0, i32 0, i32 0) + br label %merge + + right: + br label %merge + + merge: + %val.unrelocated = phi i8 addrspace(1)* [ %arg, %left ], [ %ptr, %right ] + %c = icmp eq i8 addrspace(1)* %val.unrelocated, %arg + ret void +} + +; This test checks that dead branch (right) does not conflict with live branch (left). +define void @test3(i8 addrspace(1)* %arg, i1 %cond) gc "statepoint-example" { +; CHECK-LABEL: Verifying gc pointers in function: test3 +; CHECK: No illegal uses found by SafepointIRVerifier in: test3 + begin: + %ptr = getelementptr i8, i8 addrspace(1)* %arg, i64 4 + br i1 false, label %right, label %left + + left: + %safepoint_token = call token (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 0, i32 0, void ()* undef, i32 0, i32 0, i32 0, i32 5, i32 0, i32 -1, i32 0, i32 0, i32 0) + br label %merge + + right: + br label %merge + + merge: + %val.unrelocated = phi i8 addrspace(1)* [ %arg, %left ], [ %ptr, %right ] + %c = icmp eq i8 addrspace(1)* %val.unrelocated, %arg + ret void +} + +; This test checks that two dead branches (left and right) do not conflict. +define void @test4(i8 addrspace(1)* %arg, i1 %cond) gc "statepoint-example" { +; CHECK-LABEL: Verifying gc pointers in function: test4 +; CHECK: No illegal uses found by SafepointIRVerifier in: test4 + begin: + %ptr = getelementptr i8, i8 addrspace(1)* %arg, i64 4 + br i1 true, label %next, label %right + + next: + %safepoint_token0 = call token (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 0, i32 0, void ()* undef, i32 0, i32 0, i32 0, i32 5, i32 0, i32 -1, i32 0, i32 0, i32 0) + br i1 false, label %left, label %merge + + left: + %safepoint_token1 = call token (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 0, i32 0, void ()* undef, i32 0, i32 0, i32 0, i32 5, i32 0, i32 -1, i32 0, i32 0, i32 0) + br label %merge + + right: + br label %merge + + merge: + %val.unrelocated = phi i8 addrspace(1)* [ %arg, %left ], [ %ptr, %right ], [ %arg, %next ] + %c = icmp eq i8 addrspace(1)* %val.unrelocated, %arg + ret void +} + +; This test checks that two live branches (left and right) conflict. +define void @test5(i8 addrspace(1)* %arg, i1 %cond) gc "statepoint-example" { +; CHECK-LABEL: Verifying gc pointers in function: test5 +; CHECK-NOT: No illegal uses found by SafepointIRVerifier in: test5 + begin: + %ptr = getelementptr i8, i8 addrspace(1)* %arg, i64 4 + br i1 %cond, label %left, label %right + + left: + %safepoint_token = call token (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 0, i32 0, void ()* undef, i32 0, i32 0, i32 0, i32 5, i32 0, i32 -1, i32 0, i32 0, i32 0) + br label %merge + + right: + br label %merge + + merge: + %val.unrelocated = phi i8 addrspace(1)* [ %arg, %left ], [ %ptr, %right ] + %c = icmp eq i8 addrspace(1)* %val.unrelocated, %arg + ret void +} + +; This test checks that two live blocks do not conflict if one (right) is connected +; with a critical dead edge. +define void @test6(i8 addrspace(1)* %arg, i1 %cond) gc "statepoint-example" { +; CHECK-LABEL: Verifying gc pointers in function: test6 +; CHECK: No illegal uses found by SafepointIRVerifier in: test6 + begin: + %ptr = getelementptr i8, i8 addrspace(1)* %arg, i64 4 + br i1 %cond, label %left, label %right + + left: + %safepoint_token = call token (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 0, i32 0, void ()* undef, i32 0, i32 0, i32 0, i32 5, i32 0, i32 -1, i32 0, i32 0, i32 0) + br label %merge + + right: + br i1 false, label %merge, label %exit + + merge: + %val.unrelocated = phi i8 addrspace(1)* [ %arg, %left ], [ %ptr, %right ] + %c = icmp eq i8 addrspace(1)* %val.unrelocated, %arg + ret void + + exit: + ret void +} + +; This test checks that two live blocks do not conflict if one (right) is connected +; with a critical dead edge right->merge. +define void @test7(i8 addrspace(1)* %arg, i1 %cond) gc "statepoint-example" { +; CHECK-LABEL: Verifying gc pointers in function: test7 +; CHECK: No illegal uses found by SafepointIRVerifier in: test7 + begin: + %ptr = getelementptr i8, i8 addrspace(1)* %arg, i64 4 + br i1 %cond, label %merge, label %right + + right: + %safepoint_token = call token (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 0, i32 0, void ()* undef, i32 0, i32 0, i32 0, i32 5, i32 0, i32 -1, i32 0, i32 0, i32 0) + br i1 false, label %merge, label %exit + + merge: + %val.unrelocated = phi i8 addrspace(1)* [ %arg, %begin ], [ %ptr, %right ] + %c = icmp eq i8 addrspace(1)* %val.unrelocated, %arg + ret void + + exit: + ret void +}