diff options
author | Vladislav Khmelevsky <och95@yandex.ru> | 2022-01-19 22:06:06 +0300 |
---|---|---|
committer | Vladislav Khmelevsky <och95@yandex.ru> | 2022-01-19 22:06:26 +0300 |
commit | bb8e7ebaad0d05b3458631dcf60dc3b9eb77f06a (patch) | |
tree | b47951f15021808823e75ecb805a210fa5c9044b /bolt | |
parent | e67430cca40455d31b95b088a88fa3b16a37ea34 (diff) |
[BOLT] Remove unreachable uncond branch after return
This patch fixes the removal of unreachable uncondtional branch located
after return instruction.
Vladislav Khmelevsky,
Advanced Software Technology Lab, Huawei
Reviewed By: Amir
Differential Revision: https://reviews.llvm.org/D117677
Diffstat (limited to 'bolt')
-rw-r--r-- | bolt/lib/Core/BinaryFunction.cpp | 3 | ||||
-rw-r--r-- | bolt/test/AArch64/jmp-after-ret.s | 24 | ||||
-rw-r--r-- | bolt/test/X86/jmp-after-ret.s | 24 |
3 files changed, 50 insertions, 1 deletions
diff --git a/bolt/lib/Core/BinaryFunction.cpp b/bolt/lib/Core/BinaryFunction.cpp index 5b81dfaf4e17..9d55a837f2a3 100644 --- a/bolt/lib/Core/BinaryFunction.cpp +++ b/bolt/lib/Core/BinaryFunction.cpp @@ -2031,7 +2031,8 @@ bool BinaryFunction::buildCFG(MCPlusBuilder::AllocatorIdTy AllocatorId) { assert(PrevInstr && "no previous instruction for a fall through"); if (MIB->isUnconditionalBranch(Instr) && !MIB->isUnconditionalBranch(*PrevInstr) && - !MIB->getConditionalTailCall(*PrevInstr)) { + !MIB->getConditionalTailCall(*PrevInstr) && + !MIB->isReturn(*PrevInstr)) { // Temporarily restore inserter basic block. InsertBB = PrevBB; } else { diff --git a/bolt/test/AArch64/jmp-after-ret.s b/bolt/test/AArch64/jmp-after-ret.s new file mode 100644 index 000000000000..8c6a842cd437 --- /dev/null +++ b/bolt/test/AArch64/jmp-after-ret.s @@ -0,0 +1,24 @@ +## This test checks that the unreachable unconditional branch is removed +## if it is located after return instruction. + +# REQUIRES: system-linux + +# RUN: llvm-mc -filetype=obj -triple aarch64-unknown-unknown \ +# RUN: %s -o %t.o +# RUN: %clang %cflags %t.o -o %t.exe -Wl,-q +# RUN: llvm-bolt %t.exe -o %t.bolt | FileCheck %s + +# CHECK: UCE removed 1 blocks + + .text + .align 4 + .global main + .type main, %function +main: + b.eq 1f + ret + b main +1: + mov x1, #1 + ret + .size main, .-main diff --git a/bolt/test/X86/jmp-after-ret.s b/bolt/test/X86/jmp-after-ret.s new file mode 100644 index 000000000000..5e4af99a737d --- /dev/null +++ b/bolt/test/X86/jmp-after-ret.s @@ -0,0 +1,24 @@ +## This test checks that the unreachable unconditional branch is removed +## if it is located after return instruction. + +# REQUIRES: system-linux + +# RUN: llvm-mc -filetype=obj -triple x86_64-unknown-unknown \ +# RUN: %s -o %t.o +# RUN: %clang %cflags %t.o -o %t.exe -Wl,-q +# RUN: llvm-bolt %t.exe -o %t.bolt | FileCheck %s + +# CHECK: UCE removed 1 blocks + + .text + .globl main + .type main, %function + .size main, .Lend-main +main: + je 1f + retq + jmp main +1: + movl $0x2, %ebx + retq +.Lend: |