diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp --- a/llvm/lib/IR/Verifier.cpp +++ b/llvm/lib/IR/Verifier.cpp @@ -4470,6 +4470,11 @@ visitRangeMetadata(I, Range, I.getType()); } + if (MDNode *IG = I.getMetadata(LLVMContext::MD_invariant_group)) { + Assert(isa(I) || isa(I), + "invariant.group metadata is only for loads and stores", &I); + } + if (I.getMetadata(LLVMContext::MD_nonnull)) { Assert(I.getType()->isPointerTy(), "nonnull applies only to pointer types", &I); diff --git a/llvm/test/Verifier/invariant.group.ll b/llvm/test/Verifier/invariant.group.ll new file mode 100644 --- /dev/null +++ b/llvm/test/Verifier/invariant.group.ll @@ -0,0 +1,14 @@ +; RUN: not opt -passes=verify -disable-output < %s 2>&1 | FileCheck %s + +; CHECK: invariant.group metadata is only for loads and stores +; CHECK-NEXT: alloca +; CHECK-NEXT: invariant.group metadata is only for loads and stores +; CHECK-NEXT: ret void +define void @f() { + %a = alloca i32, !invariant.group !0 + %b = load i32, i32* %a, !invariant.group !0 + store i32 43, i32* %a, !invariant.group !0 + ret void, !invariant.group !0 +} + +!0 = !{}