Add a utility function to MachineInstr for testing whether an instruction
authorDan Gohman <gohman@apple.com>
Sat, 12 Jul 2008 00:10:52 +0000 (00:10 +0000)
committerDan Gohman <gohman@apple.com>
Sat, 12 Jul 2008 00:10:52 +0000 (00:10 +0000)
has exactly one MachineMemOperand, and change some X86 lowering code to
make use of it.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@53498 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/CodeGen/MachineInstr.h
lib/Target/X86/X86InstrInfo.cpp

index 88116d2bb21bbdfc41a00027a9234ec26fb45a34..31f497469918ee0f6adc8fd816fbbe7258beaeb4 100644 (file)
@@ -115,6 +115,13 @@ public:
   { return MemOperands.end(); }
   bool memoperands_empty() const { return MemOperands.empty(); }
 
+  /// hasOneMemOperand - Return true if this instruction has exactly one
+  /// MachineMemOperand.
+  bool hasOneMemOperand() const {
+    return !memoperands_empty() &&
+           next(memoperands_begin()) == memoperands_end();
+  }
+
   /// isIdenticalTo - Return true if this instruction is identical to (same
   /// opcode and same operands as) the specified instruction.
   bool isIdenticalTo(const MachineInstr *Other) const {
index 7822ed7cb389874262413d39454976b8b38eaec2..2f191ffa4b1a4d5ad3a4b30d0434e422befc3684 100644 (file)
@@ -2030,14 +2030,10 @@ MachineInstr* X86InstrInfo::foldMemoryOperand(MachineFunction &MF,
   // Check switch flag 
   if (NoFusing) return NULL;
 
+  // Determine the alignment of the load.
   unsigned Alignment = 0;
-  for (alist<MachineMemOperand>::iterator i = LoadMI->memoperands_begin(),
-       e = LoadMI->memoperands_end(); i != e; ++i) {
-    const MachineMemOperand &MRO = *i;
-    unsigned Align = MRO.getAlignment();
-    if (Align > Alignment)
-      Alignment = Align;
-  }
+  if (LoadMI->hasOneMemOperand())
+    Alignment = LoadMI->memoperands_begin()->getAlignment();
 
   // FIXME: Move alignment requirement into tables?
   if (Alignment < 16) {