- // If this isn't guaranteed to be inbounds, give up.
- bool OOB = false;
- GEPOperator *GEPO = cast<GEPOperator>(Op1);
- if (!GEPO->isInBounds()) OOB = true;
-
- for (int i = GEPO->getNumIndices() - 1; i > 0; i--) {
- if (Constant *C = dyn_cast<Constant>(GEPO->getOperand(i)))
- if (C->isNullValue())
- continue;
-
- OOB = true;
- }
-
- // If we're guaranteed to be out of bounds just return that there's
- // no room left.
- if (OOB) return ReplaceInstUsesWith(CI, ConstantInt::get(ReturnTy, 0));
-
- // Tell the later calculation that we have an offset and what
- // it is.
- Op1 = CE->getOperand(0);
- ConstantInt *Const =
- cast<ConstantInt>(CE->getOperand(CE->getNumOperands() - 1));
- GEPindex = Const->getZExtValue();
- }