Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions llvm/lib/Transforms/Vectorize/VectorCombine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1811,6 +1811,10 @@ bool VectorCombine::scalarizeLoadExtract(Instruction &I) {
// erased in the correct order.
Worklist.push(LI);

LLVMContext &ctx = LI->getContext();
unsigned aliasScopeKind = ctx.getMDKindID("alias.scope");
unsigned noAliasKind = ctx.getMDKindID("noalias");

// Replace extracts with narrow scalar loads.
for (User *U : LI->users()) {
auto *EI = cast<ExtractElementInst>(U);
Expand All @@ -1831,6 +1835,14 @@ bool VectorCombine::scalarizeLoadExtract(Instruction &I) {
LI->getAlign(), VecTy->getElementType(), Idx, *DL);
NewLoad->setAlignment(ScalarOpAlignment);

if (MDNode *aliasScope = LI->getMetadata(aliasScopeKind)) {
NewLoad->setMetadata(aliasScopeKind, aliasScope);
}

if (MDNode *noAlias = LI->getMetadata(noAliasKind)) {
NewLoad->setMetadata(noAliasKind, noAlias);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If possible, it would be better to use getAAMetadata() and adjustForAccess() here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @nikic, thank you for the advice. I know it's a more thoughtful solution. But I'm not familiar with AA in LLVM. Can you guide me on how to use adjustForAccess(), like how to correctly calculate offset and type? Thanks!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The type is VecTy->getElementType(). The offset would be Idx * the type size like here:

if (auto *C = dyn_cast<ConstantInt>(Idx))
return commonAlignment(VectorAlignment,
C->getZExtValue() * DL.getTypeStoreSize(ScalarType));

The problem is if Idx is a variable. In that case the offset is unknown. So I would make the whole logic conditional on the dyn_cast<ConstantInt>(Idx) case.


replaceValue(*EI, *NewLoad);
}

Expand Down