-// DoInsertArrayCast - If the argument value has a pointer type, and if the
-// argument value is used as an array, insert a cast before the specified
-// basic block iterator that casts the value to an array pointer. Return the
-// new cast instruction (in the CastResult var), or null if no cast is inserted.
-//
-static bool DoInsertArrayCast(Method *CurMeth, Value *V, BasicBlock *BB,
- BasicBlock::iterator &InsertBefore,
- CastInst *&CastResult) {
- const PointerType *ThePtrType = dyn_cast<PointerType>(V->getType());
- if (!ThePtrType) return false;
- bool InsertCast = false;
-
- for (Value::use_iterator I = V->use_begin(), E = V->use_end(); I != E; ++I) {
- Instruction *Inst = cast<Instruction>(*I);
- switch (Inst->getOpcode()) {
- default: break; // Not an interesting use...
- case Instruction::Add: // It's being used as an array index!
- //case Instruction::Sub:
- InsertCast = true;
- break;
- case Instruction::Cast: // There is already a cast instruction!
- if (const PointerType *PT = dyn_cast<const PointerType>(Inst->getType()))
- if (const ArrayType *AT = dyn_cast<const ArrayType>(PT->getValueType()))
- if (AT->getElementType() == ThePtrType->getValueType()) {
- // Cast already exists! Return the existing one!
- CastResult = cast<CastInst>(Inst);
- return false; // No changes made to program though...
- }
- break;
+ // Scan all of the uses, looking for any uses that are not add
+ // instructions. If we have non-adds, do not make this transformation.
+ //
+ for (Value::use_iterator I = CI->use_begin(), E = CI->use_end();
+ I != E; ++I) {
+ if (BinaryOperator *BO = dyn_cast<BinaryOperator>(*I)) {
+ if (BO->getOpcode() != Instruction::Add)
+ return false;
+ } else {
+ return false;