[llvm-commits] [llvm] r113665 - in /llvm/trunk: include/llvm/Target/TargetInstrInfo.h lib/CodeGen/PeepholeOptimizer.cpp lib/Target/ARM/ARMBaseInstrInfo.cpp lib/Target/ARM/ARMBaseInstrInfo.h

Bill Wendling isanbard at gmail.com
Fri Sep 10 16:34:19 PDT 2010


Author: void
Date: Fri Sep 10 18:34:19 2010
New Revision: 113665

URL: http://llvm.org/viewvc/llvm-project?rev=113665&view=rev
Log:
Move some of the decision logic for converting an instruction into one that sets
the 'zero' bit down into the back-end. There are other cases where this logic
isn't sufficient, so they should be handled separately.

Modified:
    llvm/trunk/include/llvm/Target/TargetInstrInfo.h
    llvm/trunk/lib/CodeGen/PeepholeOptimizer.cpp
    llvm/trunk/lib/Target/ARM/ARMBaseInstrInfo.cpp
    llvm/trunk/lib/Target/ARM/ARMBaseInstrInfo.h

Modified: llvm/trunk/include/llvm/Target/TargetInstrInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Target/TargetInstrInfo.h?rev=113665&r1=113664&r2=113665&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Target/TargetInstrInfo.h (original)
+++ llvm/trunk/include/llvm/Target/TargetInstrInfo.h Fri Sep 10 18:34:19 2010
@@ -585,11 +585,10 @@
     return false;
   }
 
-  /// ConvertToSetZeroFlag - Convert the instruction to set the zero flag so
-  /// that we can remove a "comparison with zero".  Update the iterator *only*
-  /// if a transformation took place.
-  virtual bool ConvertToSetZeroFlag(MachineInstr * /*Instr*/,
-                                    MachineInstr * /*CmpInstr*/,
+  /// ConvertToSetZeroFlag - Convert the instruction supplying the argument to
+  /// the comparison into one that sets the zero bit in the flags
+  /// register. Update the iterator *only* if a transformation took place.
+  virtual bool ConvertToSetZeroFlag(MachineInstr * /*CmpInstr*/,
                                     MachineBasicBlock::iterator &) const {
     return false;
   }

Modified: llvm/trunk/lib/CodeGen/PeepholeOptimizer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/PeepholeOptimizer.cpp?rev=113665&r1=113664&r2=113665&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/PeepholeOptimizer.cpp (original)
+++ llvm/trunk/lib/CodeGen/PeepholeOptimizer.cpp Fri Sep 10 18:34:19 2010
@@ -240,16 +240,11 @@
   unsigned SrcReg;
   int CmpValue;
   if (!TII->AnalyzeCompare(MI, SrcReg, CmpValue) ||
-      TargetRegisterInfo::isPhysicalRegister(SrcReg) || CmpValue != 0)
-    return false;
-
-  MachineRegisterInfo::def_iterator DI = MRI->def_begin(SrcReg);
-  if (llvm::next(DI) != MRI->def_end())
-    // Only support one definition.
+      TargetRegisterInfo::isPhysicalRegister(SrcReg))
     return false;
 
   // Attempt to convert the defining instruction to set the "zero" flag.
-  if (TII->ConvertToSetZeroFlag(&*DI, MI, NextIter)) {
+  if (TII->ConvertToSetZeroFlag(MI, NextIter)) {
     ++NumEliminated;
     return true;
   }

Modified: llvm/trunk/lib/Target/ARM/ARMBaseInstrInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/ARMBaseInstrInfo.cpp?rev=113665&r1=113664&r2=113665&view=diff
==============================================================================
--- llvm/trunk/lib/Target/ARM/ARMBaseInstrInfo.cpp (original)
+++ llvm/trunk/lib/Target/ARM/ARMBaseInstrInfo.cpp Fri Sep 10 18:34:19 2010
@@ -1377,12 +1377,25 @@
   return false;
 }
 
-/// ConvertToSetZeroFlag - Convert the instruction to set the "zero" flag so
-/// that we can remove a "comparison with zero". Update the iterator *only* if a
-/// transformation took place.
+/// ConvertToSetZeroFlag - Convert the instruction supplying the argument to the
+/// comparison into one that sets the zero bit in the flags register. Update the
+/// iterator *only* if a transformation took place.
 bool ARMBaseInstrInfo::
-ConvertToSetZeroFlag(MachineInstr *MI, MachineInstr *CmpInstr,
+ConvertToSetZeroFlag(MachineInstr *CmpInstr,
                      MachineBasicBlock::iterator &MII) const {
+  unsigned SrcReg;
+  int CmpValue;
+  if (!AnalyzeCompare(CmpInstr, SrcReg, CmpValue) || CmpValue != 0)
+    return false;
+
+  MachineRegisterInfo &MRI = CmpInstr->getParent()->getParent()->getRegInfo();
+  MachineRegisterInfo::def_iterator DI = MRI.def_begin(SrcReg);
+  if (llvm::next(DI) != MRI.def_end())
+    // Only support one definition.
+    return false;
+
+  MachineInstr *MI = &*DI;
+
   // Conservatively refuse to convert an instruction which isn't in the same BB
   // as the comparison.
   if (MI->getParent() != CmpInstr->getParent())

Modified: llvm/trunk/lib/Target/ARM/ARMBaseInstrInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/ARMBaseInstrInfo.h?rev=113665&r1=113664&r2=113665&view=diff
==============================================================================
--- llvm/trunk/lib/Target/ARM/ARMBaseInstrInfo.h (original)
+++ llvm/trunk/lib/Target/ARM/ARMBaseInstrInfo.h Fri Sep 10 18:34:19 2010
@@ -346,8 +346,7 @@
 
   /// ConvertToSetZeroFlag - Convert the instruction to set the zero flag so
   /// that we can remove a "comparison with zero".
-  virtual bool ConvertToSetZeroFlag(MachineInstr *Instr,
-                                    MachineInstr *CmpInstr,
+  virtual bool ConvertToSetZeroFlag(MachineInstr *CmpInstr,
                                     MachineBasicBlock::iterator &MII) const;
 
   virtual unsigned getNumMicroOps(const MachineInstr *MI,





More information about the llvm-commits mailing list