summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Target/X86/X86ISelPattern.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2005-01-17 06:48:02 +0000
committerChris Lattner <sabre@nondot.org>2005-01-17 06:48:02 +0000
commitb72ea1b7192bcf4437d10a9769b2817fc8ac2e42 (patch)
tree96f19f5937806e2fb7ad4accf2b8964e13a38794 /llvm/lib/Target/X86/X86ISelPattern.cpp
parenta8b2929f45f4da2916422c713ebc73c8158a0a92 (diff)
downloadbcm5719-llvm-b72ea1b7192bcf4437d10a9769b2817fc8ac2e42.tar.gz
bcm5719-llvm-b72ea1b7192bcf4437d10a9769b2817fc8ac2e42.zip
Codegen this:
int %foo(int %X) { %T = add int %X, 13 %S = mul int %T, 3 ret int %S } as this: mov %ECX, DWORD PTR [%ESP + 4] lea %EAX, DWORD PTR [%ECX + 2*%ECX + 39] ret instead of this: mov %ECX, DWORD PTR [%ESP + 4] mov %EAX, %ECX add %EAX, 13 imul %EAX, %EAX, 3 ret llvm-svn: 19633
Diffstat (limited to 'llvm/lib/Target/X86/X86ISelPattern.cpp')
-rw-r--r--llvm/lib/Target/X86/X86ISelPattern.cpp18
1 files changed, 18 insertions, 0 deletions
diff --git a/llvm/lib/Target/X86/X86ISelPattern.cpp b/llvm/lib/Target/X86/X86ISelPattern.cpp
index 7a623e5b414..5f98524c552 100644
--- a/llvm/lib/Target/X86/X86ISelPattern.cpp
+++ b/llvm/lib/Target/X86/X86ISelPattern.cpp
@@ -1636,6 +1636,24 @@ unsigned ISel::SelectExpr(SDOperand N) {
}
}
+ // Fold common multiplies into LEA instructions.
+ if (Node->getOpcode() == ISD::MUL && N.getValueType() == MVT::i32) {
+ switch ((int)CN->getValue()) {
+ default: break;
+ case 3:
+ case 5:
+ case 9:
+ X86AddressMode AM;
+ // Remove N from exprmap so SelectAddress doesn't get confused.
+ ExprMap.erase(N);
+ SelectAddress(N, AM);
+ // Restore it to the map.
+ ExprMap[N] = Result;
+ addFullAddress(BuildMI(BB, X86::LEA32r, 4, Result), AM);
+ return Result;
+ }
+ }
+
switch (N.getValueType()) {
default: assert(0 && "Cannot xor this type!");
case MVT::i1:
OpenPOWER on IntegriCloud