diff --git a/llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp b/llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp --- a/llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp +++ b/llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp @@ -795,9 +795,9 @@ IRBuilder<> Builder(&I); LoadInst *NewLoad = nullptr, *LI1 = LOps.Root; + IntegerType *WiderType = IntegerType::get(I.getContext(), LOps.LoadSize); // TTI based checks if we want to proceed with wider load - bool Allowed = - TTI.isTypeLegal(IntegerType::get(I.getContext(), LOps.LoadSize)); + bool Allowed = TTI.isTypeLegal(WiderType); if (!Allowed) return false; @@ -811,9 +811,9 @@ // New load can be generated Value *Load1Ptr = LI1->getPointerOperand(); Builder.SetInsertPoint(LI1); - NewLoad = Builder.CreateAlignedLoad( - IntegerType::get(Load1Ptr->getContext(), LOps.LoadSize), Load1Ptr, - LI1->getAlign(), LI1->isVolatile(), ""); + Value *NewPtr = Builder.CreateBitCast(Load1Ptr, WiderType->getPointerTo()); + NewLoad = Builder.CreateAlignedLoad(WiderType, NewPtr, LI1->getAlign(), + LI1->isVolatile(), ""); NewLoad->takeName(LI1); // Set the New Load AATags Metadata. if (LOps.AATags)