Skip to content

Commit b449280

Browse files
clin111dstutt
andauthored
[AggressiveInstCombine] Fix cases where non-opaque pointers are used (#7021)
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 Co-authored-by: David Stuttard <[email protected]>
1 parent 332e4ee commit b449280

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -795,9 +795,9 @@ static bool foldConsecutiveLoads(Instruction &I, const DataLayout &DL,
795795
IRBuilder<> Builder(&I);
796796
LoadInst *NewLoad = nullptr, *LI1 = LOps.Root;
797797

798+
IntegerType *WiderType = IntegerType::get(I.getContext(), LOps.LoadSize);
798799
// TTI based checks if we want to proceed with wider load
799-
bool Allowed =
800-
TTI.isTypeLegal(IntegerType::get(I.getContext(), LOps.LoadSize));
800+
bool Allowed = TTI.isTypeLegal(WiderType);
801801
if (!Allowed)
802802
return false;
803803

@@ -811,9 +811,9 @@ static bool foldConsecutiveLoads(Instruction &I, const DataLayout &DL,
811811
// New load can be generated
812812
Value *Load1Ptr = LI1->getPointerOperand();
813813
Builder.SetInsertPoint(LI1);
814-
NewLoad = Builder.CreateAlignedLoad(
815-
IntegerType::get(Load1Ptr->getContext(), LOps.LoadSize), Load1Ptr,
816-
LI1->getAlign(), LI1->isVolatile(), "");
814+
Value *NewPtr = Builder.CreateBitCast(Load1Ptr, WiderType->getPointerTo(AS));
815+
NewLoad = Builder.CreateAlignedLoad(WiderType, NewPtr, LI1->getAlign(),
816+
LI1->isVolatile(), "");
817817
NewLoad->takeName(LI1);
818818
// Set the New Load AATags Metadata.
819819
if (LOps.AATags)

0 commit comments

Comments
 (0)