[llvm] f00cd27 - [Verifier] Verify llvm.access.group metadata
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Mon Mar 14 08:16:44 PDT 2022
Author: Nikita Popov
Date: 2022-03-14T16:16:36+01:00
New Revision: f00cd27646c08ee2ab68a561c3db34dd8f259951
URL: https://github.com/llvm/llvm-project/commit/f00cd27646c08ee2ab68a561c3db34dd8f259951
DIFF: https://github.com/llvm/llvm-project/commit/f00cd27646c08ee2ab68a561c3db34dd8f259951.diff
LOG: [Verifier] Verify llvm.access.group metadata
According to LangRef, an access scope must have zero operands and
be distinct. The access group may either be a single access scope
or a list of access scopes.
LoopInfo may assert if this is not the case.
Added:
llvm/test/Verifier/access_group.ll
Modified:
llvm/lib/IR/Verifier.cpp
llvm/test/Transforms/SimplifyCFG/X86/combine-parallel-mem-md.ll
Removed:
################################################################################
diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index 66218ba6d1453..bc6f6757311f1 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -464,6 +464,7 @@ class Verifier : public InstVisitor<Verifier>, VerifierSupport {
void visitAnnotationMetadata(MDNode *Annotation);
void visitAliasScopeMetadata(const MDNode *MD);
void visitAliasScopeListMetadata(const MDNode *MD);
+ void visitAccessGroupMetadata(const MDNode *MD);
template <class Ty> bool isValidMetadataArray(const MDTuple &N);
#define HANDLE_SPECIALIZED_MDNODE_LEAF(CLASS) void visit##CLASS(const CLASS &N);
@@ -4477,6 +4478,24 @@ void Verifier::visitAliasScopeListMetadata(const MDNode *MD) {
}
}
+void Verifier::visitAccessGroupMetadata(const MDNode *MD) {
+ auto IsValidAccessScope = [](const MDNode *MD) {
+ return MD->getNumOperands() == 0 && MD->isDistinct();
+ };
+
+ // It must be either an access scope itself...
+ if (IsValidAccessScope(MD))
+ return;
+
+ // ...or a list of access scopes.
+ for (const MDOperand &Op : MD->operands()) {
+ const MDNode *OpMD = dyn_cast<MDNode>(Op);
+ Assert(OpMD != nullptr, "Access scope list must consist of MDNodes", MD);
+ Assert(IsValidAccessScope(OpMD),
+ "Access scope list contains invalid access scope", MD);
+ }
+}
+
/// verifyInstruction - Verify that an instruction is well formed.
///
void Verifier::visitInstruction(Instruction &I) {
@@ -4641,6 +4660,9 @@ void Verifier::visitInstruction(Instruction &I) {
if (MDNode *MD = I.getMetadata(LLVMContext::MD_alias_scope))
visitAliasScopeListMetadata(MD);
+ if (MDNode *MD = I.getMetadata(LLVMContext::MD_access_group))
+ visitAccessGroupMetadata(MD);
+
if (MDNode *AlignMD = I.getMetadata(LLVMContext::MD_align)) {
Assert(I.getType()->isPointerTy(), "align applies only to pointer types",
&I);
diff --git a/llvm/test/Transforms/SimplifyCFG/X86/combine-parallel-mem-md.ll b/llvm/test/Transforms/SimplifyCFG/X86/combine-parallel-mem-md.ll
index 019e757ab2225..d6462d5566d0f 100644
--- a/llvm/test/Transforms/SimplifyCFG/X86/combine-parallel-mem-md.ll
+++ b/llvm/test/Transforms/SimplifyCFG/X86/combine-parallel-mem-md.ll
@@ -17,30 +17,30 @@ entry:
for.body: ; preds = %cond.end, %entry
%indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %cond.end ]
%arrayidx = getelementptr inbounds i32, i32* %p, i64 %indvars.iv
- %0 = load i32, i32* %arrayidx, align 4, !llvm.access.group !0
+ %0 = load i32, i32* %arrayidx, align 4, !llvm.access.group !10
%cmp1 = icmp eq i32 %0, 0
br i1 %cmp1, label %cond.true, label %cond.false
cond.false: ; preds = %for.body
%arrayidx3 = getelementptr inbounds i32, i32* %res, i64 %indvars.iv
- %v = load i32, i32* %arrayidx3, align 4, !llvm.access.group !0
+ %v = load i32, i32* %arrayidx3, align 4, !llvm.access.group !10
%arrayidx7 = getelementptr inbounds i32, i32* %d, i64 %indvars.iv
- %1 = load i32, i32* %arrayidx7, align 4, !llvm.access.group !0
+ %1 = load i32, i32* %arrayidx7, align 4, !llvm.access.group !10
%add = add nsw i32 %1, %v
br label %cond.end
cond.true: ; preds = %for.body
%arrayidx4 = getelementptr inbounds i32, i32* %res, i64 %indvars.iv
- %w = load i32, i32* %arrayidx4, align 4, !llvm.access.group !0
+ %w = load i32, i32* %arrayidx4, align 4, !llvm.access.group !10
%arrayidx8 = getelementptr inbounds i32, i32* %d, i64 %indvars.iv
- %2 = load i32, i32* %arrayidx8, align 4, !llvm.access.group !0
+ %2 = load i32, i32* %arrayidx8, align 4, !llvm.access.group !10
%add2 = add nsw i32 %2, %w
br label %cond.end
cond.end: ; preds = %for.body, %cond.false
%cond = phi i32 [ %add, %cond.false ], [ %add2, %cond.true ]
%arrayidx9 = getelementptr inbounds i32, i32* %res, i64 %indvars.iv
- store i32 %cond, i32* %arrayidx9, align 4, !llvm.access.group !0
+ store i32 %cond, i32* %arrayidx9, align 4, !llvm.access.group !10
%indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
%exitcond = icmp eq i64 %indvars.iv.next, 16
br i1 %exitcond, label %for.end, label %for.body, !llvm.loop !0
diff --git a/llvm/test/Verifier/access_group.ll b/llvm/test/Verifier/access_group.ll
new file mode 100644
index 0000000000000..b1fdb4eea364d
--- /dev/null
+++ b/llvm/test/Verifier/access_group.ll
@@ -0,0 +1,18 @@
+; RUN: not llvm-as < %s -o /dev/null 2>&1 | FileCheck %s
+
+define void @test(i8* %p) {
+; CHECK: Access scope list contains invalid access scope
+ load i8, i8* %p, !llvm.access.group !1
+; CHECK: Access scope list must consist of MDNodes
+ load i8, i8* %p, !llvm.access.group !2
+; CHECK-NOT: Access scope
+ load i8, i8* %p, !llvm.access.group !3
+ load i8, i8* %p, !llvm.access.group !4
+ ret void
+}
+
+!0 = !{}
+!1 = !{!0}
+!2 = !{!"foo"}
+!3 = distinct !{}
+!4 = !{!3}
More information about the llvm-commits
mailing list