[mips] Fix a bug in MipsLongBranch::replaceBranch, which was erasing
authorAkira Hatanaka <ahatanaka@mips.com>
Fri, 4 Oct 2013 20:51:40 +0000 (20:51 +0000)
committerAkira Hatanaka <ahatanaka@mips.com>
Fri, 4 Oct 2013 20:51:40 +0000 (20:51 +0000)
instructions in delay slots along with the original branch instructions.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@191978 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/Mips/MipsLongBranch.cpp
test/CodeGen/Mips/longbranch.ll

index 971176ec8fb0218ea767b970158221f6aefe31ee..06bb14a383c4ff6da446914d6ded4496d2d7851f 100644 (file)
@@ -237,6 +237,11 @@ void MipsLongBranch::replaceBranch(MachineBasicBlock &MBB, Iter Br,
 
   MIB.addMBB(MBBOpnd);
 
+  // Bundle the instruction in the delay slot to the newly created branch
+  // and erase the original branch.
+  assert(Br->isBundledWithSucc());
+  MachineBasicBlock::instr_iterator II(Br);
+  MIBundleBuilder(&*MIB).append(llvm::next(II)->removeFromBundle());
   Br->eraseFromParent();
 }
 
index 1a4f79c191e14c59ff0ee95e7a99fa8c09f9b125..af192d0e9217031d8887b4e36601d89e3dcc0c3f 100644 (file)
@@ -1,13 +1,17 @@
-; RUN: llc -march=mipsel -force-mips-long-branch < %s | FileCheck %s -check-prefix=O32
-; RUN: llc -march=mips64el -mcpu=mips64 -mattr=n64  -force-mips-long-branch < %s | FileCheck %s -check-prefix=N64
+; RUN: llc -march=mipsel -force-mips-long-branch -disable-mips-delay-filler < %s | FileCheck %s -check-prefix=O32
+; RUN: llc -march=mips64el -mcpu=mips64 -mattr=n64  -force-mips-long-branch -disable-mips-delay-filler < %s | FileCheck %s -check-prefix=N64
 
 @g0 = external global i32
 
 define void @foo1(i32 %s) nounwind {
 entry:
+; O32: nop
+; O32: addiu $sp, $sp, -8
 ; O32: bal
 ; O32: lui $1, 0
 ; O32: addiu $1, $1, {{[0-9]+}} 
+; N64: nop
+; N64: daddiu $sp, $sp, -16
 ; N64: lui $1, 0
 ; N64: daddiu $1, $1, 0
 ; N64: dsll $1, $1, 16