[PATCH] D122929: [BOLT] Fix remove double jumps peephole pass

Vladislav Khmelevsky via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 1 12:04:58 PDT 2022


yota9 updated this revision to Diff 419827.
yota9 added a comment.

Add test description


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D122929/new/

https://reviews.llvm.org/D122929

Files:
  bolt/lib/Passes/BinaryPasses.cpp
  bolt/test/AArch64/ext-double-jump.s


Index: bolt/test/AArch64/ext-double-jump.s
===================================================================
--- /dev/null
+++ 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
Index: bolt/lib/Passes/BinaryPasses.cpp
===================================================================
--- bolt/lib/Passes/BinaryPasses.cpp
+++ 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);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D122929.419827.patch
Type: text/x-patch
Size: 1557 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220401/c906435e/attachment.bin>


More information about the llvm-commits mailing list