Fold TRUNCATE (LOAD P) into a smaller load from P.
authorChris Lattner <sabre@nondot.org>
Wed, 12 Jan 2005 02:19:06 +0000 (02:19 +0000)
committerChris Lattner <sabre@nondot.org>
Wed, 12 Jan 2005 02:19:06 +0000 (02:19 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@19494 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/X86/X86ISelPattern.cpp

index dacd5133c1d127ec28824f0316e6f3f7fd2431d4..34d13564707ff4aed743e09c0a79767f5a0bf70d 100644 (file)
@@ -410,6 +410,7 @@ unsigned ISel::ComputeRegPressure(SDOperand O) {
   
     Result = MaxRegUse+NumExtraMaxRegUsers;
   }
+
   //std::cerr << " WEIGHT: " << Result << " ";  N->dump(); std::cerr << "\n";
   return Result;
 }
@@ -1106,6 +1107,20 @@ unsigned ISel::SelectExpr(SDOperand N) {
     return Result;
   }
   case ISD::TRUNCATE:
+    // Fold TRUNCATE (LOAD P) into a smaller load from P.
+    if (isFoldableLoad(N.getOperand(0))) {
+      switch (N.getValueType()) {
+      default: assert(0 && "Unknown truncate!");
+      case MVT::i1:
+      case MVT::i8:  Opc = X86::MOV8rm;  break;
+      case MVT::i16: Opc = X86::MOV16rm; break;
+      }
+      X86AddressMode AM;
+      EmitFoldedLoad(N.getOperand(0), AM);
+      addFullAddress(BuildMI(BB, Opc, 4, Result), AM);
+      return Result;
+    }
+
     // Handle cast of LARGER int to SMALLER int using a move to EAX followed by
     // a move out of AX or AL.
     switch (N.getOperand(0).getValueType()) {