[llvm] r323136 - [ARM] Cleanup part of ARMBaseInstrInfo::optimizeCompareInstr (NFCI).

Joel Galenson via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 22 09:53:47 PST 2018


Author: jgalenson
Date: Mon Jan 22 09:53:47 2018
New Revision: 323136

URL: http://llvm.org/viewvc/llvm-project?rev=323136&view=rev
Log:
[ARM] Cleanup part of ARMBaseInstrInfo::optimizeCompareInstr (NFCI).

As noted in another review, this loop is confusing.  This commit cleans it up
somewhat.

Differential Revision: https://reviews.llvm.org/D42312

Modified:
    llvm/trunk/lib/Target/ARM/ARMBaseInstrInfo.cpp

Modified: llvm/trunk/lib/Target/ARM/ARMBaseInstrInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/ARMBaseInstrInfo.cpp?rev=323136&r1=323135&r2=323136&view=diff
==============================================================================
--- llvm/trunk/lib/Target/ARM/ARMBaseInstrInfo.cpp (original)
+++ llvm/trunk/lib/Target/ARM/ARMBaseInstrInfo.cpp Mon Jan 22 09:53:47 2018
@@ -2736,35 +2736,31 @@ bool ARMBaseInstrInfo::optimizeCompareIn
     }
     I = CmpInstr;
     E = MI;
-  } else if (E != B) {
-    // Allow the loop below to search E (which was initially MI).  Since MI and
-    // SubAdd have different tests, even if that instruction could not be MI, it
-    // could still potentially be SubAdd.
-    --E;
   }
 
   // Check that CPSR isn't set between the comparison instruction and the one we
   // want to change. At the same time, search for SubAdd.
   const TargetRegisterInfo *TRI = &getRegisterInfo();
-  --I;
-  for (; I != E; --I) {
-    const MachineInstr &Instr = *I;
+  do {
+    const MachineInstr &Instr = *--I;
 
     // Check whether CmpInstr can be made redundant by the current instruction.
-    if (isRedundantFlagInstr(&CmpInstr, SrcReg, SrcReg2, CmpValue, &*I)) {
+    if (isRedundantFlagInstr(&CmpInstr, SrcReg, SrcReg2, CmpValue, &Instr)) {
       SubAdd = &*I;
       break;
     }
 
+    // Allow E (which was initially MI) to be SubAdd but do not search before E.
+    if (I == E)
+      break;
+
     if (Instr.modifiesRegister(ARM::CPSR, TRI) ||
         Instr.readsRegister(ARM::CPSR, TRI))
       // This instruction modifies or uses CPSR after the one we want to
       // change. We can't do this transformation.
       return false;
 
-    if (I == B)
-      break;
-  }
+  } while (I != B);
 
   // Return false if no candidates exist.
   if (!MI && !SubAdd)




More information about the llvm-commits mailing list