OSDN Git Service

[PowerPC] fix up in redundant compare elimination
authorHiroshi Inoue <inouehrs@jp.ibm.com>
Wed, 15 Nov 2017 04:23:26 +0000 (04:23 +0000)
committerHiroshi Inoue <inouehrs@jp.ibm.com>
Wed, 15 Nov 2017 04:23:26 +0000 (04:23 +0000)
This patch fixes a potential problem in my previous commit (https://reviews.llvm.org/rL312514) by introducing an additional check.

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

lib/Target/PowerPC/PPCMIPeephole.cpp

index 80b7ac2..0a84fe3 100644 (file)
@@ -814,8 +814,12 @@ static bool eligibleForCompareElimination(MachineBasicBlock &MBB,
           !MRI->hasOneNonDBGUse(CndReg))
         return false;
 
-      // We skip this BB if a physical register is used in comparison.
       MachineInstr *CMPI = MRI->getVRegDef(CndReg);
+      // We assume compare and branch are in the same BB for ease of analysis.
+      if (CMPI->getParent() != &BB)
+        return false;
+
+      // We skip this BB if a physical register is used in comparison.
       for (MachineOperand &MO : CMPI->operands())
         if (MO.isReg() && !TargetRegisterInfo::isVirtualRegister(MO.getReg()))
           return false;
@@ -921,7 +925,7 @@ bool PPCMIPeephole::eliminateRedundantCompare(void) {
     //
     // As partially redundant case, we additionally handle if MBB2 has one
     // additional predecessor, which has only one successor (MBB2).
-    // In this case, we move the compre instruction originally in MBB2 into
+    // In this case, we move the compare instruction originally in MBB2 into
     // MBBtoMoveCmp. This partially redundant case is typically appear by
     // compiling a while loop; here, MBBtoMoveCmp is the loop preheader.
     //