X-Git-Url: http://plrg.eecs.uci.edu/git/?p=oota-llvm.git;a=blobdiff_plain;f=lib%2FTarget%2FAArch64%2FAArch64InstrInfo.cpp;h=c9c982ed7b5949bd8d1d897450d708146b2bbfc5;hp=f398117de953b2f2d9a55673cfbaa0ca7c11ecab;hb=0e59c4e3e8f8e105834d137cccb1e1bb731b5a13;hpb=81d225b93d55ec44d6e79f2d95440f250f3df064 diff --git a/lib/Target/AArch64/AArch64InstrInfo.cpp b/lib/Target/AArch64/AArch64InstrInfo.cpp index f398117de95..c9c982ed7b5 100644 --- a/lib/Target/AArch64/AArch64InstrInfo.cpp +++ b/lib/Target/AArch64/AArch64InstrInfo.cpp @@ -217,6 +217,25 @@ bool AArch64InstrInfo::ReverseBranchCondition( return false; } +// XXX-update: Returns whether we can remove a conditional branch instruction. +// If it's one that is mannually added by us, then don't remove it (return +// false). All their successors are the same. +static bool shouldRemoveConditionalBranch(MachineInstr* I) { + auto* MBB = I->getParent(); + assert(isCondBranchOpcode(I->getOpcode())); + bool SameSuccessor = true; + MachineBasicBlock* BB = nullptr; + for (auto* Succ : MBB->successors()) { + if (!BB) { + BB = Succ; + } + if (BB != Succ) { + SameSuccessor = false; + } + } + return !SameSuccessor; +} + unsigned AArch64InstrInfo::RemoveBranch(MachineBasicBlock &MBB) const { MachineBasicBlock::iterator I = MBB.getLastNonDebugInstr(); if (I == MBB.end()) @@ -226,6 +245,11 @@ unsigned AArch64InstrInfo::RemoveBranch(MachineBasicBlock &MBB) const { !isCondBranchOpcode(I->getOpcode())) return 0; + // XXX-update: Don't remove fake conditional branches. + if (isCondBranchOpcode(I->getOpcode()) && !shouldRemoveConditionalBranch(I)) { + return 0; + } + // Remove the branch. I->eraseFromParent(); @@ -237,6 +261,11 @@ unsigned AArch64InstrInfo::RemoveBranch(MachineBasicBlock &MBB) const { if (!isCondBranchOpcode(I->getOpcode())) return 1; + // XXX-update: Don't remove fake conditional branches. + if (!shouldRemoveConditionalBranch(I)) { + return 1; + } + // Remove the branch. I->eraseFromParent(); return 2;