- // Now we must actually perform the scaling operation to get an
- // appropriate value to add in... but the scale has to be done in the
- // appropriate destination pointer type, so cast the index value now.
- //
- // Cast the base index pointer
- CastInst *IdxValue = new CastInst(Expr.Var, GEP->getType());
- BI = BB->getInstList().insert(BI, IdxValue)+1;
-
- // Case the scale amount as well...
- CastInst *ScaleAmt =
- new CastInst(ConstPoolUInt::get(Type::ULongTy, Scale), GEP->getType());
- BI = BB->getInstList().insert(BI, ScaleAmt)+1;
-
- // Insert the multiply now. Make sure to make the constant the second arg
- Instruction *ScaledVal =
- BinaryOperator::create(Instruction::Mul, IdxValue, ScaleAmt);
- BI = BB->getInstList().insert(BI, ScaledVal)+1;
-
- // Now insert an ADD to actually adjust the pointer...
- Instruction *AddInst =
- BinaryOperator::create(Instruction::Add, GEP, ScaledVal);
- BI = BB->getInstList().insert(BI, AddInst)+1;
-
- PRINT_PEEPHOLE4("add-to-gep:out1", IdxValue, ScaleAmt, ScaledVal,
- AddInst);
- AddrSrc = AddInst;
- }
-
- // Insert a cast of the pointer to array of X to be a pointer to the
- // element of the array.
- //
- // Insert a cast of the "rest" of the offset to the appropriate
- // pointer type.
- CastInst *ACI = new CastInst(AddrSrc, AT->getElementType());
- BI = BB->getInstList().insert(BI, ACI)+1;
- AddrSrc = ACI;
-
- } else {
- assert(Offset == ActualOffset && "GEP to middle of non array!");
- assert(Scale == 1 && "Scale factor for expr that is not an array idx!");
- }
-
- Instruction *NCI = new CastInst(AddrSrc, AddOp1->getType());