diff options
| author | Chris Lattner <sabre@nondot.org> | 2004-07-21 21:28:26 +0000 |
|---|---|---|
| committer | Chris Lattner <sabre@nondot.org> | 2004-07-21 21:28:26 +0000 |
| commit | fac8452acf42f5156c74c9d5fe55288c56a9f815 (patch) | |
| tree | 392036a2f51cd047ce98d6bd625fff055aff0a2c /llvm | |
| parent | 902dcf07290919f960b06695c16d8c72c521c01a (diff) | |
| download | bcm5719-llvm-fac8452acf42f5156c74c9d5fe55288c56a9f815.tar.gz bcm5719-llvm-fac8452acf42f5156c74c9d5fe55288c56a9f815.zip | |
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
llvm-svn: 15090
Diffstat (limited to 'llvm')
| -rw-r--r-- | llvm/lib/Target/X86/InstSelectSimple.cpp | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/llvm/lib/Target/X86/InstSelectSimple.cpp b/llvm/lib/Target/X86/InstSelectSimple.cpp index cb57c12889b..4b43896d37d 100644 --- a/llvm/lib/Target/X86/InstSelectSimple.cpp +++ b/llvm/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(); } } |

