[PATCH] D42312: [ARM] Cleanup part of ARMBaseInstrInfo::optimizeCompareInstr (NFCI).

Joel Galenson via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 19 12:37:36 PST 2018


jgalenson created this revision.
jgalenson added reviewers: efriedma, rogfer01, eastig.
Herald added subscribers: kristof.beyls, javed.absar, aemerson.

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


https://reviews.llvm.org/D42312

Files:
  lib/Target/ARM/ARMBaseInstrInfo.cpp


Index: lib/Target/ARM/ARMBaseInstrInfo.cpp
===================================================================
--- lib/Target/ARM/ARMBaseInstrInfo.cpp
+++ lib/Target/ARM/ARMBaseInstrInfo.cpp
@@ -2736,35 +2736,29 @@
     }
     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;
     }
 
-    if (Instr.modifiesRegister(ARM::CPSR, TRI) ||
-        Instr.readsRegister(ARM::CPSR, TRI))
+    if ((Instr.modifiesRegister(ARM::CPSR, TRI) ||
+         Instr.readsRegister(ARM::CPSR, TRI)) && I != E)
       // 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;
-  }
+    // Do not search before E (which was initially MI) or the beginning of the
+    // basic block. We consider E itself because it could still be SubAdd.
+  } while (I != B && I != E);
 
   // Return false if no candidates exist.
   if (!MI && !SubAdd)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D42312.130674.patch
Type: text/x-patch
Size: 1742 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180119/e0c7a229/attachment.bin>


More information about the llvm-commits mailing list