[llvm-commits] CVS: llvm/lib/Target/X86/InstSelectSimple.cpp

Chris Lattner lattner at cs.uiuc.edu
Wed Jul 21 14:28:36 PDT 2004



Changes in directory llvm/lib/Target/X86:

InstSelectSimple.cpp updated: 1.274 -> 1.275

---
Log message:

Fix cases where we generated horrible code like this:

        mov %EDI, 12
        add %EDI, %ECX
        mov %ECX, 12
        add %ECX, %EDX
        mov %EDX, 12
        add %EDX, %ESI

instead (really!) generate this:

        add %ECX, 12
        add %EDX, 12
        add %ESI, 12



---
Diffs of the changes:  (+7 -1)

Index: llvm/lib/Target/X86/InstSelectSimple.cpp
diff -u llvm/lib/Target/X86/InstSelectSimple.cpp:1.274 llvm/lib/Target/X86/InstSelectSimple.cpp:1.275
--- llvm/lib/Target/X86/InstSelectSimple.cpp:1.274	Mon Jul 19 18:50:57 2004
+++ llvm/lib/Target/X86/InstSelectSimple.cpp	Wed Jul 21 16:28:26 2004
@@ -2967,8 +2967,9 @@
       // Okay, we found a user.  If the load is the first operand and there is
       // no second operand load, reverse the operand ordering.  Note that this
       // can fail for a subtract (ie, no change will be made).
+      bool Swapped = false;
       if (!isa<LoadInst>(User->getOperand(1)))
-        cast<BinaryOperator>(User)->swapOperands();
+        Swapped = !cast<BinaryOperator>(User)->swapOperands();
       
       // Okay, now that everything is set up, if this load is used by the second
       // operand, and if there are no instructions that invalidate the load
@@ -2985,6 +2986,11 @@
            User->getOpcode() == Instruction::Div) &&
           isSafeToFoldLoadIntoInstruction(I, *User))
         return;  // Eliminate the load!
+
+      // If we swapped the operands to the instruction, but couldn't fold the
+      // load anyway, swap them back.  We don't want to break add X, int 
+      // folding.
+      if (Swapped) cast<BinaryOperator>(User)->swapOperands();
     }
   }
 





More information about the llvm-commits mailing list