[llvm-commits] [llvm] r110539 - in /llvm/trunk: include/llvm/Target/TargetInstrInfo.h lib/CodeGen/OptimizeCmps.cpp lib/Target/ARM/ARMBaseInstrInfo.cpp lib/Target/ARM/ARMBaseInstrInfo.h lib/Target/ARM/ARMInstrThumb2.td

Bill Wendling isanbard at gmail.com
Sat Aug 7 22:04:59 PDT 2010


Author: void
Date: Sun Aug  8 00:04:59 2010
New Revision: 110539

URL: http://llvm.org/viewvc/llvm-project?rev=110539&view=rev
Log:
Use the "isCompare" machine instruction attribute instead of calling the
relatively expensive comparison analyzer on each instruction. Also rename the
comparison analyzer method to something more in line with what it actually does.

This pass is will eventually be folded into the Machine CSE pass.

Modified:
    llvm/trunk/include/llvm/Target/TargetInstrInfo.h
    llvm/trunk/lib/CodeGen/OptimizeCmps.cpp
    llvm/trunk/lib/Target/ARM/ARMBaseInstrInfo.cpp
    llvm/trunk/lib/Target/ARM/ARMBaseInstrInfo.h
    llvm/trunk/lib/Target/ARM/ARMInstrThumb2.td

Modified: llvm/trunk/include/llvm/Target/TargetInstrInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Target/TargetInstrInfo.h?rev=110539&r1=110538&r2=110539&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Target/TargetInstrInfo.h (original)
+++ llvm/trunk/include/llvm/Target/TargetInstrInfo.h Sun Aug  8 00:04:59 2010
@@ -577,17 +577,17 @@
   virtual ScheduleHazardRecognizer*
   CreateTargetPostRAHazardRecognizer(const InstrItineraryData&) const = 0;
 
-  /// isCompareInstr - If the machine instruction is a comparison instruction,
-  /// then return true. Also return the source register in SrcReg and the value
-  /// it compares against in CmpValue.
-  virtual bool isCompareInstr(const MachineInstr *MI,
+  /// AnalyzeCompare - For a comparison instruction, return the source register
+  /// in SrcReg and the value it compares against in CmpValue. Return true if
+  /// the comparison instruction can be analyzed.
+  virtual bool AnalyzeCompare(const MachineInstr *MI,
                               unsigned &SrcReg, int &CmpValue) const {
     return false;
   }
 
-  /// convertToSetZeroFlag - Convert the instruction to set the zero flag so
+  /// ConvertToSetZeroFlag - Convert the instruction to set the zero flag so
   /// that we can remove a "comparison with zero".
-  virtual bool convertToSetZeroFlag(MachineInstr *Instr,
+  virtual bool ConvertToSetZeroFlag(MachineInstr *Instr,
                                     MachineInstr *CmpInstr) const {
     return false;
   }

Modified: llvm/trunk/lib/CodeGen/OptimizeCmps.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/OptimizeCmps.cpp?rev=110539&r1=110538&r2=110539&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/OptimizeCmps.cpp (original)
+++ llvm/trunk/lib/CodeGen/OptimizeCmps.cpp Sun Aug  8 00:04:59 2010
@@ -72,9 +72,8 @@
   // physical register, we can try to optimize it.
   unsigned SrcReg;
   int CmpValue;
-  if (!TII->isCompareInstr(MI, SrcReg, CmpValue) ||
-      TargetRegisterInfo::isPhysicalRegister(SrcReg) ||
-      CmpValue != 0)
+  if (!TII->AnalyzeCompare(MI, SrcReg, CmpValue) ||
+      TargetRegisterInfo::isPhysicalRegister(SrcReg) || CmpValue != 0)
     return false;
 
   MachineRegisterInfo::def_iterator DI = MRI->def_begin(SrcReg);
@@ -83,7 +82,7 @@
     return false;
 
   // Attempt to convert the defining instruction to set the "zero" flag.
-  if (TII->convertToSetZeroFlag(&*DI, MI)) {
+  if (TII->ConvertToSetZeroFlag(&*DI, MI)) {
     ++NumEliminated;
     return true;
   }
@@ -104,7 +103,8 @@
     for (MachineBasicBlock::iterator
            MII = MBB->begin(), ME = MBB->end(); MII != ME; ) {
       MachineInstr *MI = &*MII++;
-      Changed |= OptimizeCmpInstr(MI, MBB);
+      if (MI->getDesc().isCompare())
+        Changed |= OptimizeCmpInstr(MI, MBB);
     }
   }
 

Modified: llvm/trunk/lib/Target/ARM/ARMBaseInstrInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/ARMBaseInstrInfo.cpp?rev=110539&r1=110538&r2=110539&view=diff
==============================================================================
--- llvm/trunk/lib/Target/ARM/ARMBaseInstrInfo.cpp (original)
+++ llvm/trunk/lib/Target/ARM/ARMBaseInstrInfo.cpp Sun Aug  8 00:04:59 2010
@@ -1355,7 +1355,7 @@
 }
 
 bool ARMBaseInstrInfo::
-isCompareInstr(const MachineInstr *MI, unsigned &SrcReg, int &CmpValue) const {
+AnalyzeCompare(const MachineInstr *MI, unsigned &SrcReg, int &CmpValue) const {
   switch (MI->getOpcode()) {
   default: break;
   case ARM::t2CMPri:
@@ -1368,10 +1368,10 @@
   return false;
 }
 
-/// convertToSetZeroFlag - Convert the instruction to set the "zero" flag so
+/// ConvertToSetZeroFlag - Convert the instruction to set the "zero" flag so
 /// that we can remove a "comparison with zero".
 bool ARMBaseInstrInfo::
-convertToSetZeroFlag(MachineInstr *MI, MachineInstr *CmpInstr) const {
+ConvertToSetZeroFlag(MachineInstr *MI, MachineInstr *CmpInstr) const {
   // 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=110539&r1=110538&r2=110539&view=diff
==============================================================================
--- llvm/trunk/lib/Target/ARM/ARMBaseInstrInfo.h (original)
+++ llvm/trunk/lib/Target/ARM/ARMBaseInstrInfo.h Sun Aug  8 00:04:59 2010
@@ -337,15 +337,15 @@
     return NumInstrs && NumInstrs == 1;
   }
 
-  /// isCompareInstr - If the machine instruction is a comparison instruction,
-  /// then return true. Also return the source register in SrcReg and the value
-  /// it compares against in CmpValue.
-  virtual bool isCompareInstr(const MachineInstr *MI, unsigned &SrcReg,
+  /// AnalyzeCompare - For a comparison instruction, return the source register
+  /// in SrcReg and the value it compares against in CmpValue. Return true if
+  /// the comparison instruction can be analyzed.
+  virtual bool AnalyzeCompare(const MachineInstr *MI, unsigned &SrcReg,
                               int &CmpValue) const;
 
-  /// convertToSetZeroFlag - Convert the instruction to set the zero flag so
+  /// ConvertToSetZeroFlag - Convert the instruction to set the zero flag so
   /// that we can remove a "comparison with zero".
-  virtual bool convertToSetZeroFlag(MachineInstr *Instr,
+  virtual bool ConvertToSetZeroFlag(MachineInstr *Instr,
                                     MachineInstr *CmpInstr) const;
 };
 

Modified: llvm/trunk/lib/Target/ARM/ARMInstrThumb2.td
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/ARMInstrThumb2.td?rev=110539&r1=110538&r2=110539&view=diff
==============================================================================
--- llvm/trunk/lib/Target/ARM/ARMInstrThumb2.td (original)
+++ llvm/trunk/lib/Target/ARM/ARMInstrThumb2.td Sun Aug  8 00:04:59 2010
@@ -2155,11 +2155,12 @@
 //===----------------------------------------------------------------------===//
 //  Comparison Instructions...
 //
-
+let isCompare = 1 in {
 defm t2CMP  : T2I_cmp_irs<0b1101, "cmp",
                           BinOpFrag<(ARMcmp node:$LHS, node:$RHS)>>;
 defm t2CMPz : T2I_cmp_irs<0b1101, "cmp",
                           BinOpFrag<(ARMcmpZ node:$LHS, node:$RHS)>>;
+}
 
 //FIXME: Disable CMN, as CCodes are backwards from compare expectations
 //       Compare-to-zero still works out, just not the relationals





More information about the llvm-commits mailing list