diff --git a/llvm/lib/Transforms/Scalar/SROA.cpp b/llvm/lib/Transforms/Scalar/SROA.cpp index 42d1d9a437bb2..028bcde5a51d7 100644 --- a/llvm/lib/Transforms/Scalar/SROA.cpp +++ b/llvm/lib/Transforms/Scalar/SROA.cpp @@ -3221,12 +3221,16 @@ class AllocaSliceRewriter : public InstVisitor { return V; Type *SplatIntTy = Type::getIntNTy(VTy->getContext(), Size * 8); - V = IRB.CreateMul( - IRB.CreateZExt(V, SplatIntTy, "zext"), - IRB.CreateUDiv(Constant::getAllOnesValue(SplatIntTy), - IRB.CreateZExt(Constant::getAllOnesValue(V->getType()), - SplatIntTy)), - "isplat"); + if (isa(V)) { + V = UndefValue::get(VTy); + } else { + V = IRB.CreateMul( + IRB.CreateZExt(V, SplatIntTy, "zext"), + IRB.CreateUDiv(Constant::getAllOnesValue(SplatIntTy), + IRB.CreateZExt(Constant::getAllOnesValue(V->getType()), + SplatIntTy)), + "isplat"); + } return V; }