From: Chad Rosier Date: Wed, 25 Jan 2017 15:56:59 +0000 (+0000) Subject: [AArch64] Minor code refactoring. NFC. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c7fa24790c43c5785ca06e18063737380e9f8f4d;p=llvm [AArch64] Minor code refactoring. NFC. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293063 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Target/AArch64/AArch64RedundantCopyElimination.cpp b/lib/Target/AArch64/AArch64RedundantCopyElimination.cpp index 8f45e6a80a3..45fd358a99b 100644 --- a/lib/Target/AArch64/AArch64RedundantCopyElimination.cpp +++ b/lib/Target/AArch64/AArch64RedundantCopyElimination.cpp @@ -70,14 +70,10 @@ static bool guaranteesZeroRegInBlock(MachineInstr &MI, MachineBasicBlock *MBB) { unsigned Opc = MI.getOpcode(); // Check if the current basic block is the target block to which the // CBZ/CBNZ instruction jumps when its Wt/Xt is zero. - if ((Opc == AArch64::CBZW || Opc == AArch64::CBZX) && - MBB == MI.getOperand(1).getMBB()) - return true; - else if ((Opc == AArch64::CBNZW || Opc == AArch64::CBNZX) && - MBB != MI.getOperand(1).getMBB()) - return true; - - return false; + return ((Opc == AArch64::CBZW || Opc == AArch64::CBZX) && + MBB == MI.getOperand(1).getMBB()) || + ((Opc == AArch64::CBNZW || Opc == AArch64::CBNZX) && + MBB != MI.getOperand(1).getMBB()); } bool AArch64RedundantCopyElimination::optimizeCopy(MachineBasicBlock *MBB) { @@ -85,9 +81,14 @@ bool AArch64RedundantCopyElimination::optimizeCopy(MachineBasicBlock *MBB) { if (MBB->pred_size() != 1) return false; + // Check if the predecessor has two successors, implying the block ends in a + // conditional branch. MachineBasicBlock *PredMBB = *MBB->pred_begin(); + if (PredMBB->succ_size() != 2) + return false; + MachineBasicBlock::iterator CompBr = PredMBB->getLastNonDebugInstr(); - if (CompBr == PredMBB->end() || PredMBB->succ_size() != 2) + if (CompBr == PredMBB->end()) return false; ++CompBr;