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

Chris Lattner lattner at cs.uiuc.edu
Sun Jan 16 22:48:17 PST 2005



Changes in directory llvm/lib/Target/X86:

X86ISelPattern.cpp updated: 1.61 -> 1.62
---
Log message:

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




---
Diffs of the changes:  (+18 -0)

Index: llvm/lib/Target/X86/X86ISelPattern.cpp
diff -u llvm/lib/Target/X86/X86ISelPattern.cpp:1.61 llvm/lib/Target/X86/X86ISelPattern.cpp:1.62
--- llvm/lib/Target/X86/X86ISelPattern.cpp:1.61	Mon Jan 17 00:26:58 2005
+++ llvm/lib/Target/X86/X86ISelPattern.cpp	Mon Jan 17 00:48:02 2005
@@ -1636,6 +1636,24 @@
         }
       }
 
+      // 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:






More information about the llvm-commits mailing list