[PATCH] D117677: [BOLT] Remove unreachable uncond branch after return
Vladislav Khmelevsky via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 19 11:06:53 PST 2022
This revision was automatically updated to reflect the committed changes.
yota9 marked 2 inline comments as done.
Closed by commit rGbb8e7ebaad0d: [BOLT] Remove unreachable uncond branch after return (authored by yota9).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D117677/new/
https://reviews.llvm.org/D117677
Files:
bolt/lib/Core/BinaryFunction.cpp
bolt/test/AArch64/jmp-after-ret.s
bolt/test/X86/jmp-after-ret.s
Index: bolt/test/X86/jmp-after-ret.s
===================================================================
--- /dev/null
+++ 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:
Index: bolt/test/AArch64/jmp-after-ret.s
===================================================================
--- /dev/null
+++ 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
Index: bolt/lib/Core/BinaryFunction.cpp
===================================================================
--- bolt/lib/Core/BinaryFunction.cpp
+++ bolt/lib/Core/BinaryFunction.cpp
@@ -2031,7 +2031,8 @@
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 {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D117677.401342.patch
Type: text/x-patch
Size: 2022 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220119/900850c9/attachment.bin>
More information about the llvm-commits
mailing list