diff --git a/bolt/lib/Passes/BinaryPasses.cpp b/bolt/lib/Passes/BinaryPasses.cpp --- a/bolt/lib/Passes/BinaryPasses.cpp +++ b/bolt/lib/Passes/BinaryPasses.cpp @@ -697,8 +697,8 @@ // Succ will be null in the tail call case. In this case we // need to explicitly add a tail call instruction. MCInst *Branch = Pred->getLastNonPseudoInstr(); - if (Branch && MIB->isUnconditionalBranch(*Branch)) { - assert(MIB->getTargetSymbol(*Branch) == BB.getLabel()); + if (Branch && MIB->isUnconditionalBranch(*Branch) && + MIB->getTargetSymbol(*Branch) == BB.getLabel()) { Pred->removeSuccessor(&BB); Pred->eraseInstruction(Pred->findInstruction(Branch)); Pred->addTailCallInstruction(SuccSym); diff --git a/bolt/test/AArch64/ext-double-jump.s b/bolt/test/AArch64/ext-double-jump.s new file mode 100644 --- /dev/null +++ b/bolt/test/AArch64/ext-double-jump.s @@ -0,0 +1,28 @@ +# This test checks that remove double jumps pass works properly with +# non-local branches. + +# RUN: llvm-mc -filetype=obj -triple aarch64-unknown-unknown %s -o %t.o +# RUN: %clang %cflags -nostartfiles -nodefaultlibs %t.o -o %t.exe -Wl,-q +# RUN: llvm-bolt %t.exe -o %t.bolt -peepholes=double-jumps + + .text + .align 4 + .global dummy1 + .type dummy1, %function +dummy1: + mov x2, x0 + ret + + .global dummy2 + .type dummy2, %function +dummy2: + mov x1, x0 + ret + + .global _start + .type _start, %function +_start: + cbz x10, 1f + b dummy1 +1: + b dummy2