aboutsummaryrefslogtreecommitdiff
path: root/lib/Target/X86/InstSelectSimple.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2004-07-21 21:28:26 +0000
committerChris Lattner <sabre@nondot.org>2004-07-21 21:28:26 +0000
commit3dbb504081c24a8cac35c4ac230a1c03a6a090e0 (patch)
tree8c4fda3d41c648955aa7c4ccc085fe689225904f /lib/Target/X86/InstSelectSimple.cpp
parent7848e68c1635ccba5a08d55314d4e5aed5ab54b9 (diff)
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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@15090 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Target/X86/InstSelectSimple.cpp')
-rw-r--r--lib/Target/X86/InstSelectSimple.cpp8
1 files changed, 7 insertions, 1 deletions
diff --git a/lib/Target/X86/InstSelectSimple.cpp b/lib/Target/X86/InstSelectSimple.cpp
index cb57c12889..4b43896d37 100644
--- a/lib/Target/X86/InstSelectSimple.cpp
+++ b/lib/Target/X86/InstSelectSimple.cpp
@@ -2967,8 +2967,9 @@ void ISel::visitLoadInst(LoadInst &I) {
// 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 @@ void ISel::visitLoadInst(LoadInst &I) {
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();
}
}