Skip to content

Commit

Permalink
[LV][LSV][SLP] Drop some typed pointer bitcasts
Browse files Browse the repository at this point in the history
Differential Revision: https://reviews.llvm.org/D156736
  • Loading branch information
bjope committed Aug 2, 2023
1 parent fd05c34 commit 408cc94
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 25 deletions.
9 changes: 4 additions & 5 deletions llvm/lib/Transforms/Vectorize/LoadStoreVectorizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -900,9 +900,9 @@ bool Vectorizer::vectorizeChain(Chain &C) {

// Chain is in offset order, so C[0] is the instr with the lowest offset,
// i.e. the root of the vector.
Value *Bitcast = Builder.CreateBitCast(
getLoadStorePointerOperand(C[0].Inst), VecTy->getPointerTo(AS));
VecInst = Builder.CreateAlignedLoad(VecTy, Bitcast, Alignment);
VecInst = Builder.CreateAlignedLoad(VecTy,
getLoadStorePointerOperand(C[0].Inst),
Alignment);

unsigned VecIdx = 0;
for (const ChainElem &E : C) {
Expand Down Expand Up @@ -976,8 +976,7 @@ bool Vectorizer::vectorizeChain(Chain &C) {
// i.e. the root of the vector.
VecInst = Builder.CreateAlignedStore(
Vec,
Builder.CreateBitCast(getLoadStorePointerOperand(C[0].Inst),
VecTy->getPointerTo(AS)),
getLoadStorePointerOperand(C[0].Inst),
Alignment);
}

Expand Down
6 changes: 1 addition & 5 deletions llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2630,11 +2630,7 @@ void InnerLoopVectorizer::vectorizeInterleaveGroup(
if (auto *gep = dyn_cast<GetElementPtrInst>(AddrPart->stripPointerCasts()))
InBounds = gep->isInBounds();
AddrPart = Builder.CreateGEP(ScalarTy, AddrPart, Idx, "", InBounds);

// Cast to the vector pointer type.
unsigned AddressSpace = AddrPart->getType()->getPointerAddressSpace();
Type *PtrTy = VecTy->getPointerTo(AddressSpace);
AddrParts.push_back(Builder.CreateBitCast(AddrPart, PtrTy));
AddrParts.push_back(AddrPart);
}

State.setDebugLocFromInst(Instr);
Expand Down
24 changes: 9 additions & 15 deletions llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10256,8 +10256,7 @@ Value *BoUpSLP::vectorizeTree(TreeEntry *E) {
case Instruction::ExtractValue: {
auto *LI = cast<LoadInst>(E->getSingleOperand(0));
Builder.SetInsertPoint(LI);
auto *PtrTy = PointerType::get(VecTy, LI->getPointerAddressSpace());
Value *Ptr = Builder.CreateBitCast(LI->getOperand(0), PtrTy);
Value *Ptr = LI->getPointerOperand();
LoadInst *V = Builder.CreateAlignedLoad(VecTy, Ptr, LI->getAlign());
Value *NewV = propagateMetadata(V, E->Scalars);
NewV = FinalShuffle(NewV, E);
Expand Down Expand Up @@ -10599,28 +10598,23 @@ Value *BoUpSLP::vectorizeTree(TreeEntry *E) {
}
case Instruction::Store: {
auto *SI = cast<StoreInst>(VL0);
unsigned AS = SI->getPointerAddressSpace();

setInsertPointAfterBundle(E);

Value *VecValue = vectorizeOperand(E, 0);
VecValue = FinalShuffle(VecValue, E);

Value *ScalarPtr = SI->getPointerOperand();
Value *VecPtr = Builder.CreateBitCast(
ScalarPtr, VecValue->getType()->getPointerTo(AS));
Value *Ptr = SI->getPointerOperand();
StoreInst *ST =
Builder.CreateAlignedStore(VecValue, VecPtr, SI->getAlign());
Builder.CreateAlignedStore(VecValue, Ptr, SI->getAlign());

// The pointer operand uses an in-tree scalar, so add the new BitCast or
// StoreInst to ExternalUses to make sure that an extract will be
// generated in the future.
if (TreeEntry *Entry = getTreeEntry(ScalarPtr)) {
// The pointer operand uses an in-tree scalar, so add the new StoreInst to
// ExternalUses to make sure that an extract will be generated in the
// future.
if (TreeEntry *Entry = getTreeEntry(Ptr)) {
// Find which lane we need to extract.
unsigned FoundLane = Entry->findLaneForValue(ScalarPtr);
ExternalUses.push_back(ExternalUser(
ScalarPtr, ScalarPtr != VecPtr ? cast<User>(VecPtr) : ST,
FoundLane));
unsigned FoundLane = Entry->findLaneForValue(Ptr);
ExternalUses.push_back(ExternalUser(Ptr, ST, FoundLane));
}

Value *V = propagateMetadata(ST, E->Scalars);
Expand Down

0 comments on commit 408cc94

Please sign in to comment.