Index: lib/Target/NVPTX/NVPTXInstrInfo.cpp =================================================================== --- lib/Target/NVPTX/NVPTXInstrInfo.cpp +++ lib/Target/NVPTX/NVPTXInstrInfo.cpp @@ -179,7 +179,7 @@ return true; // If the block ends with NVPTX::GOTO and NVPTX:CBranch, handle it. - if (SecondLastInst->getOpcode() == NVPTX::CBranch && + if (SecondLastInst && SecondLastInst->getOpcode() == NVPTX::CBranch && LastInst->getOpcode() == NVPTX::GOTO) { TBB = SecondLastInst->getOperand(1).getMBB(); Cond.push_back(SecondLastInst->getOperand(0)); @@ -189,7 +189,7 @@ // If the block ends with two NVPTX:GOTOs, handle it. The second one is not // executed, so remove it. - if (SecondLastInst->getOpcode() == NVPTX::GOTO && + if (SecondLastInst && SecondLastInst->getOpcode() == NVPTX::GOTO && LastInst->getOpcode() == NVPTX::GOTO) { TBB = SecondLastInst->getOperand(0).getMBB(); I = LastInst;