Index: llvm/lib/IR/Instructions.cpp =================================================================== --- llvm/lib/IR/Instructions.cpp +++ llvm/lib/IR/Instructions.cpp @@ -1247,9 +1247,10 @@ : Instruction(Type::getVoidTy(IfTrue->getContext()), Instruction::Br, OperandTraits::op_end(this) - 3, 3, InsertBefore) { - Op<-1>() = IfTrue; - Op<-2>() = IfFalse; + // Assign in order of operand index to make use-list order predictable. Op<-3>() = Cond; + Op<-2>() = IfFalse; + Op<-1>() = IfTrue; #ifndef NDEBUG AssertOK(); #endif @@ -1266,9 +1267,10 @@ BasicBlock *InsertAtEnd) : Instruction(Type::getVoidTy(IfTrue->getContext()), Instruction::Br, OperandTraits::op_end(this) - 3, 3, InsertAtEnd) { - Op<-1>() = IfTrue; - Op<-2>() = IfFalse; + // Assign in order of operand index to make use-list order predictable. Op<-3>() = Cond; + Op<-2>() = IfFalse; + Op<-1>() = IfTrue; #ifndef NDEBUG AssertOK(); #endif @@ -1278,12 +1280,13 @@ : Instruction(Type::getVoidTy(BI.getContext()), Instruction::Br, OperandTraits::op_end(this) - BI.getNumOperands(), BI.getNumOperands()) { - Op<-1>() = BI.Op<-1>(); + // Assign in order of operand index to make use-list order predictable. if (BI.getNumOperands() != 1) { assert(BI.getNumOperands() == 3 && "BR can have 1 or 3 operands!"); Op<-3>() = BI.Op<-3>(); Op<-2>() = BI.Op<-2>(); } + Op<-1>() = BI.Op<-1>(); SubclassOptionalData = BI.SubclassOptionalData; } Index: llvm/test/Assembler/br-single-destination.ll =================================================================== --- /dev/null +++ llvm/test/Assembler/br-single-destination.ll @@ -0,0 +1,11 @@ +; RUN: llvm-as < %s -disable-output 2>&1 | FileCheck %s -allow-empty +; CHECK-NOT: error +; CHECK-NOT: warning +; RUN: verify-uselistorder < %s + +define void @f1(i1 %cmp) { +entry: + br i1 %cmp, label %branch, label %branch +branch: + unreachable +}