From d1d7d2235ced0a959bf0d2513f8adc50c0e5efd8 Mon Sep 17 00:00:00 2001 From: David Stuttard Date: Mon, 3 Oct 2022 19:21:18 +0100 Subject: [PATCH] [AggressiveInstCombine] Fix cases where non-opaque pointers are used In the case of non-opaque pointers, when combining consecutive loads, need to bitcast the pointer source to the combined type size, otherwise asserts are triggered. Differential Revision: https://reviews.llvm.org/D135249 --- .../Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp b/llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp index 359aa28..0ac9881 100644 --- a/llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp +++ b/llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp @@ -795,9 +795,9 @@ static bool foldConsecutiveLoads(Instruction &I, const DataLayout &DL, 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 @@ static bool foldConsecutiveLoads(Instruction &I, const DataLayout &DL, // 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(AS)); + NewLoad = Builder.CreateAlignedLoad(WiderType, NewPtr, LI1->getAlign(), + LI1->isVolatile(), ""); NewLoad->takeName(LI1); // Set the New Load AATags Metadata. if (LOps.AATags) -- 2.7.4