Index: lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp =================================================================== --- lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp +++ lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp @@ -882,6 +882,10 @@ } void SelectionDAGBuilder::visit(const Instruction &I) { + // Don't create any nodes after a TRAP. + if (getControlRoot()->getOpcode() == ISD::TRAP) + return; + // Set up outgoing PHI node register values before emitting the terminator. if (isa(&I)) { HandlePHINodesInSuccessorBlocks(I.getParent()); Index: lib/Target/AArch64/AArch64InstrInfo.td =================================================================== --- lib/Target/AArch64/AArch64InstrInfo.td +++ lib/Target/AArch64/AArch64InstrInfo.td @@ -1298,7 +1298,8 @@ //===----------------------------------------------------------------------===// // Exception generation instructions. //===----------------------------------------------------------------------===// -def BRK : ExceptionGeneration<0b001, 0b00, "brk">; +let isTerminator = 1 in // Consider trap a terminator + def BRK : ExceptionGeneration<0b001, 0b00, "brk">; def DCPS1 : ExceptionGeneration<0b101, 0b01, "dcps1">; def DCPS2 : ExceptionGeneration<0b101, 0b10, "dcps2">; def DCPS3 : ExceptionGeneration<0b101, 0b11, "dcps3">; Index: lib/Target/Mips/Mips16InstrInfo.td =================================================================== --- lib/Target/Mips/Mips16InstrInfo.td +++ lib/Target/Mips/Mips16InstrInfo.td @@ -634,6 +634,7 @@ // Purpose: Breakpoint // To cause a Breakpoint exception. +let isTerminator = 1 in def Break16: FRRBreakNull16_ins<"break 0", IIM16Alu>; // // Format: BTEQZ offset MIPS16e Index: lib/Target/Mips/MipsInstrInfo.td =================================================================== --- lib/Target/Mips/MipsInstrInfo.td +++ lib/Target/Mips/MipsInstrInfo.td @@ -1941,7 +1941,8 @@ ISA_MIPS2_NOT_32R6_64R6; let AdditionalPredicates = [NotInMicroMips] in { -def BREAK : MMRel, StdMMR6Rel, BRK_FT<"break">, BRK_FM<0xd>; + let isTerminator = 1 in + def BREAK : MMRel, StdMMR6Rel, BRK_FT<"break">, BRK_FM<0xd>; def SYSCALL : MMRel, SYS_FT<"syscall", uimm20, II_SYSCALL>, SYS_FM<0xc>; } def TRAP : TrapBase; Index: lib/Target/NVPTX/NVPTXInstrInfo.td =================================================================== --- lib/Target/NVPTX/NVPTXInstrInfo.td +++ lib/Target/NVPTX/NVPTXInstrInfo.td @@ -3137,7 +3137,8 @@ [(callseq_end timm:$amt1, timm:$amt2)]>; // trap instruction -def trapinst : NVPTXInst<(outs), (ins), "trap;", [(trap)]>; +let isTerminator = 1 in + def trapinst : NVPTXInst<(outs), (ins), "trap;", [(trap)]>; // Call prototype wrapper def SDTCallPrototype : SDTypeProfile<0, 1, [SDTCisInt<0>]>; Index: lib/Target/SystemZ/SystemZInstrInfo.td =================================================================== --- lib/Target/SystemZ/SystemZInstrInfo.td +++ lib/Target/SystemZ/SystemZInstrInfo.td @@ -189,10 +189,7 @@ //===----------------------------------------------------------------------===// // Unconditional trap. -// FIXME: This trap instruction should be marked as isTerminator, but there is -// currently a general bug that allows non-terminators to be placed between -// terminators. Temporarily leave this unmarked until the bug is fixed. -let isBarrier = 1, hasCtrlDep = 1 in +let isTerminator = 1, isBarrier = 1, hasCtrlDep = 1 in def Trap : Alias<4, (outs), (ins), [(trap)]>; // Conditional trap. Index: lib/Target/X86/X86InstrSystem.td =================================================================== --- lib/Target/X86/X86InstrSystem.td +++ lib/Target/X86/X86InstrSystem.td @@ -24,7 +24,8 @@ // CPU flow control instructions let mayLoad = 1, mayStore = 0, hasSideEffects = 1 in { - def TRAP : I<0x0B, RawFrm, (outs), (ins), "ud2", [(trap)]>, TB; + let isTerminator = 1 in + def TRAP : I<0x0B, RawFrm, (outs), (ins), "ud2", [(trap)]>, TB; def UD2B : I<0xB9, RawFrm, (outs), (ins), "ud2b", []>, TB; } Index: lib/Target/XCore/XCoreInstrInfo.td =================================================================== --- lib/Target/XCore/XCoreInstrInfo.td +++ lib/Target/XCore/XCoreInstrInfo.td @@ -980,7 +980,7 @@ "ecallt $a", []>; -let hasCtrlDep = 1 in +let hasCtrlDep = 1, isTerminator = 1 in def ECALLF_1r : _F1R<0b010010, (outs), (ins GRRegs:$a), "ecallf $a", []>;