diff --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp index 501a8cb6bea51..fab73c20f3f2d 100644 --- a/llvm/lib/Analysis/ConstantFolding.cpp +++ b/llvm/lib/Analysis/ConstantFolding.cpp @@ -383,7 +383,7 @@ Constant *llvm::ConstantFoldLoadThroughBitcast(Constant *C, Type *DestTy, Cast = Instruction::PtrToInt; if (CastInst::castIsValid(Cast, C, DestTy)) - return ConstantExpr::getCast(Cast, C, DestTy); + return ConstantFoldCastOperand(Cast, C, DestTy, DL); } // If this isn't an aggregate type, there is nothing we can do to drill down @@ -846,14 +846,14 @@ Constant *CastGEPIndices(Type *SrcElemTy, ArrayRef Ops, SrcElemTy, Ops.slice(1, i - 1)))) && Ops[i]->getType()->getScalarType() != IntIdxScalarTy) { Any = true; - Type *NewType = Ops[i]->getType()->isVectorTy() - ? IntIdxTy - : IntIdxScalarTy; - NewIdxs.push_back(ConstantExpr::getCast(CastInst::getCastOpcode(Ops[i], - true, - NewType, - true), - Ops[i], NewType)); + Type *NewType = + Ops[i]->getType()->isVectorTy() ? IntIdxTy : IntIdxScalarTy; + Constant *NewIdx = ConstantFoldCastOperand( + CastInst::getCastOpcode(Ops[i], true, NewType, true), Ops[i], NewType, + DL); + if (!NewIdx) + return nullptr; + NewIdxs.push_back(NewIdx); } else NewIdxs.push_back(Ops[i]); }