[llvm] r318266 - [PowerPC] fix up in redundant compare elimination

Hiroshi Inoue via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 14 20:23:26 PST 2017


Author: inouehrs
Date: Tue Nov 14 20:23:26 2017
New Revision: 318266

URL: http://llvm.org/viewvc/llvm-project?rev=318266&view=rev
Log:
[PowerPC] fix up in redundant compare elimination

This patch fixes a potential problem in my previous commit (https://reviews.llvm.org/rL312514) by introducing an additional check.


Modified:
    llvm/trunk/lib/Target/PowerPC/PPCMIPeephole.cpp

Modified: llvm/trunk/lib/Target/PowerPC/PPCMIPeephole.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/PowerPC/PPCMIPeephole.cpp?rev=318266&r1=318265&r2=318266&view=diff
==============================================================================
--- llvm/trunk/lib/Target/PowerPC/PPCMIPeephole.cpp (original)
+++ llvm/trunk/lib/Target/PowerPC/PPCMIPeephole.cpp Tue Nov 14 20:23:26 2017
@@ -814,8 +814,12 @@ static bool eligibleForCompareEliminatio
           !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::eliminateRedundantCo
     //
     // 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.
     //




More information about the llvm-commits mailing list