Fix some bugs in code I didn't mean to check in.
authorChris Lattner <sabre@nondot.org>
Thu, 13 Jan 2005 20:40:58 +0000 (20:40 +0000)
committerChris Lattner <sabre@nondot.org>
Thu, 13 Jan 2005 20:40:58 +0000 (20:40 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@19534 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Scalar/InstructionCombining.cpp

index d21ec7621520f74367978edb761a9b7dcc68dca2..9f6e712e2544c9b4ef35f3f35a0e70e3d2a78f76 100644 (file)
@@ -2112,6 +2112,7 @@ static Value *EmitGEPOffset(User *GEP, Instruction &I, InstCombiner &IC) {
                                             SIntPtrTy);
     if (Constant *OpC = dyn_cast<Constant>(Op)) {
       if (!OpC->isNullValue()) {
+        OpC = ConstantExpr::getCast(OpC, SIntPtrTy);
         Scale = ConstantExpr::getMul(OpC, Scale);
         if (Constant *RC = dyn_cast<Constant>(Result))
           Result = ConstantExpr::getAdd(RC, Scale);
@@ -2123,13 +2124,19 @@ static Value *EmitGEPOffset(User *GEP, Instruction &I, InstCombiner &IC) {
         }
       }
     } else {
-      // We'll let instcombine(mul) convert this to a shl if possible.
-      Value *Offs = 
-        IC.InsertNewInstBefore(BinaryOperator::createMul(Op, Scale,
-                                                   GEP->getName()+".idx"), I);
+      //if (Op->getType() != Scale->getType())
+      if (Size != 1) {
+        // Convert to correct type.
+        Op = IC.InsertNewInstBefore(new CastInst(Op, SIntPtrTy,
+                                                 Op->getName()+".c"), I);
+
+        // We'll let instcombine(mul) convert this to a shl if possible.
+        Op = IC.InsertNewInstBefore(BinaryOperator::createMul(Op, Scale,
+                                                    GEP->getName()+".idx"), I);
+      }
 
       // Emit an add instruction.
-      Result = IC.InsertNewInstBefore(BinaryOperator::createAdd(Offs, Result,
+      Result = IC.InsertNewInstBefore(BinaryOperator::createAdd(Op, Result,
                                                     GEP->getName()+".offs"), I);
     }
   }