Skip to content

Commit

Permalink
[IR] Add NoAliasScopeDeclInst (NFC)
Browse files Browse the repository at this point in the history
Add an intrinsic type class to represent the
llvm.experimental.noalias.scope.decl intrinsic, to make code
working with it a bit nicer by hiding the metadata extraction
from view.
  • Loading branch information
nikic committed Jan 23, 2021
1 parent c37dd3b commit c83cff4
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 20 deletions.
18 changes: 18 additions & 0 deletions llvm/include/llvm/IR/IntrinsicInst.h
Original file line number Diff line number Diff line change
Expand Up @@ -989,6 +989,24 @@ class PseudoProbeInst : public IntrinsicInst {
return cast<ConstantInt>(const_cast<Value *>(getArgOperand(1)));
}
};

class NoAliasScopeDeclInst : public IntrinsicInst {
public:
static bool classof(const IntrinsicInst *I) {
return I->getIntrinsicID() == Intrinsic::experimental_noalias_scope_decl;
}

static bool classof(const Value *V) {
return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
}

MDNode *getScopeList() const {
auto *MV =
cast<MetadataAsValue>(getOperand(Intrinsic::NoAliasScopeDeclScopeArg));
return cast<MDNode>(MV->getMetadata());
}
};

} // end namespace llvm

#endif // LLVM_IR_INTRINSICINST_H
22 changes: 7 additions & 15 deletions llvm/lib/Transforms/Utils/InlineFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -859,13 +859,8 @@ ScopedAliasMetadataDeepCloner::ScopedAliasMetadataDeepCloner(
MD.insert(M);

// We also need to clone the metadata in noalias intrinsics.
if (const auto *II = dyn_cast<IntrinsicInst>(&I))
if (II->getIntrinsicID() == Intrinsic::experimental_noalias_scope_decl)
if (const auto *M = dyn_cast<MDNode>(
cast<MetadataAsValue>(
II->getOperand(Intrinsic::NoAliasScopeDeclScopeArg))
->getMetadata()))
MD.insert(M);
if (const auto *Decl = dyn_cast<NoAliasScopeDeclInst>(&I))
MD.insert(Decl->getScopeList());
}
}
addRecursiveMetadataUses();
Expand Down Expand Up @@ -932,14 +927,11 @@ void ScopedAliasMetadataDeepCloner::remap(ValueToValueMapTy &VMap) {
if (MDNode *M = I->getMetadata(LLVMContext::MD_noalias))
I->setMetadata(LLVMContext::MD_noalias, MDMap[M]);

if (auto *II = dyn_cast<IntrinsicInst>(I))
if (II->getIntrinsicID() == Intrinsic::experimental_noalias_scope_decl) {
auto *MV = cast<MetadataAsValue>(
II->getOperand(Intrinsic::NoAliasScopeDeclScopeArg));
auto *NewMV = MetadataAsValue::get(
II->getContext(), MDMap[cast<MDNode>(MV->getMetadata())]);
II->setOperand(Intrinsic::NoAliasScopeDeclScopeArg, NewMV);
}
if (auto *Decl = dyn_cast<NoAliasScopeDeclInst>(I)) {
auto *NewMV =
MetadataAsValue::get(Decl->getContext(), MDMap[Decl->getScopeList()]);
Decl->setOperand(Intrinsic::NoAliasScopeDeclScopeArg, NewMV);
}
}
}

Expand Down
3 changes: 1 addition & 2 deletions llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -947,9 +947,8 @@ bool LoopVectorizationLegality::blockCanBePredicated(
// Do not let llvm.experimental.noalias.scope.decl block the vectorization.
// TODO: there might be cases that it should block the vectorization. Let's
// ignore those for now.
if (match(&I, m_Intrinsic<Intrinsic::experimental_noalias_scope_decl>())) {
if (isa<NoAliasScopeDeclInst>(&I))
continue;
}

// We might be able to hoist the load.
if (I.mayReadFromMemory()) {
Expand Down
5 changes: 2 additions & 3 deletions llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2882,10 +2882,9 @@ void InnerLoopVectorizer::scalarizeInstruction(Instruction *Instr, VPUser &User,

// llvm.experimental.noalias.scope.decl intrinsics must only be duplicated for
// the first lane and part.
if (auto *II = dyn_cast<IntrinsicInst>(Instr))
if (isa<NoAliasScopeDeclInst>(Instr))
if (Instance.Lane != 0 || Instance.Part != 0)
if (II->getIntrinsicID() == Intrinsic::experimental_noalias_scope_decl)
return;
return;

setDebugLocFromInst(Builder, Instr);

Expand Down

0 comments on commit c83cff4

Please sign in to comment.