aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/Target/X86/InstSelectSimple.cpp8
-rw-r--r--lib/Target/X86/X86ISelSimple.cpp8
2 files changed, 14 insertions, 2 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();
}
}
diff --git a/lib/Target/X86/X86ISelSimple.cpp b/lib/Target/X86/X86ISelSimple.cpp
index cb57c12889..4b43896d37 100644
--- a/lib/Target/X86/X86ISelSimple.cpp
+++ b/lib/Target/X86/X86ISelSimple.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();
}
}