Minor tweak to avoid an extra reg-reg copy that the register allocator has to eliminate
authorChris Lattner <sabre@nondot.org>
Tue, 6 Apr 2004 01:25:33 +0000 (01:25 +0000)
committerChris Lattner <sabre@nondot.org>
Tue, 6 Apr 2004 01:25:33 +0000 (01:25 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@12680 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/X86/InstSelectSimple.cpp
lib/Target/X86/X86ISelSimple.cpp

index 25f67ecca6ae976c62c12ad27c953af7eec8df23..6144b626a67fd0a0a3e773c7344e6e5afe32a2e9 100644 (file)
@@ -1109,12 +1109,21 @@ void ISel::promote32(unsigned targetReg, const ValueRecord &VR) {
 
   Value *Val = VR.Val;
   const Type *Ty = VR.Ty;
-  if (Val)
+  if (Val) {
     if (Constant *C = dyn_cast<Constant>(Val)) {
       Val = ConstantExpr::getCast(C, Type::IntTy);
       Ty = Type::IntTy;
     }
 
+    // If this is a simple constant, just emit a MOVri directly to avoid the
+    // copy.
+    if (ConstantInt *CI = dyn_cast<ConstantInt>(Val)) {
+      int TheVal = CI->getRawValue() & 0xFFFFFFFF;
+    BuildMI(BB, X86::MOV32ri, 1, targetReg).addImm(TheVal);
+      return;
+    }
+  }
+
   // Make sure we have the register number for this value...
   unsigned Reg = Val ? getReg(Val) : VR.Reg;
 
index 25f67ecca6ae976c62c12ad27c953af7eec8df23..6144b626a67fd0a0a3e773c7344e6e5afe32a2e9 100644 (file)
@@ -1109,12 +1109,21 @@ void ISel::promote32(unsigned targetReg, const ValueRecord &VR) {
 
   Value *Val = VR.Val;
   const Type *Ty = VR.Ty;
-  if (Val)
+  if (Val) {
     if (Constant *C = dyn_cast<Constant>(Val)) {
       Val = ConstantExpr::getCast(C, Type::IntTy);
       Ty = Type::IntTy;
     }
 
+    // If this is a simple constant, just emit a MOVri directly to avoid the
+    // copy.
+    if (ConstantInt *CI = dyn_cast<ConstantInt>(Val)) {
+      int TheVal = CI->getRawValue() & 0xFFFFFFFF;
+    BuildMI(BB, X86::MOV32ri, 1, targetReg).addImm(TheVal);
+      return;
+    }
+  }
+
   // Make sure we have the register number for this value...
   unsigned Reg = Val ? getReg(Val) : VR.Reg;