-// Peephole optimize the following instructions:
-// %t1 = cast ulong <const int> to {<...>} *
-// %t2 = add {<...>} * %SP, %t1 ;; Constant must be 2nd operand
-//
-// or
-// %t1 = cast {<...>}* %SP to int*
-// %t5 = cast ulong <const int> to int*
-// %t2 = add int* %t1, %t5 ;; int is same size as field
-//
-// Into: %t3 = getelementptr {<...>} * %SP, <element indices>
-// %t2 = cast <eltype> * %t3 to {<...>}*
-//
-static bool PeepholeOptimizeAddCast(BasicBlock *BB, BasicBlock::iterator &BI,
- Value *AddOp1, CastInst *AddOp2) {
- const CompositeType *CompTy;
- Value *OffsetVal = AddOp2->getOperand(0);
- Value *SrcPtr; // Of type pointer to struct...
-
- if ((CompTy = getPointedToComposite(AddOp1->getType()))) {
- SrcPtr = AddOp1; // Handle the first case...
- } else if (CastInst *AddOp1c = dyn_cast<CastInst>(AddOp1)) {
- SrcPtr = AddOp1c->getOperand(0); // Handle the second case...
- CompTy = getPointedToComposite(SrcPtr->getType());
- }
-
- // Only proceed if we have detected all of our conditions successfully...
- if (!CompTy || !SrcPtr || !OffsetVal->getType()->isInteger())
- return false;
-
- std::vector<Value*> Indices;
- if (!ConvertableToGEP(SrcPtr->getType(), OffsetVal, Indices, &BI))
- return false; // Not convertable... perhaps next time