+
+ if (IdxList.size() == 1) {
+ const Type *ElTy = cast<PointerType>(C->getType())->getElementType();
+ if (unsigned ElSize = ElTy->getPrimitiveSize()) {
+ // gep null, C is equal to C*sizeof(nullty). If nullty is a known llvm
+ // type, we can statically fold this.
+ Constant *R = ConstantUInt::get(Type::UIntTy, ElSize);
+ R = ConstantExpr::getCast(R, IdxList[0]->getType());
+ R = ConstantExpr::getMul(R, IdxList[0]);
+ return ConstantExpr::getCast(R, C->getType());
+ }
+ }