[PATCH] D95335: [Verifier] enable and limit llvm.experimental.noalias.scope.decl dominance checking

Jeroen Dobbelaere via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 25 01:35:46 PST 2021


jeroen.dobbelaere created this revision.
jeroen.dobbelaere added reviewers: fhahn, nikic.
Herald added subscribers: dexonsmith, hiraditya.
jeroen.dobbelaere requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Checking the llvm.experimental.noalias.scope.decl dominance can be worstcase O(N^2).

Only check this when the number of declarations in the function is 'low' (<= 1000) or when compiling with EXPENSIVE_CHECKS.


https://reviews.llvm.org/D95335

Files:
  llvm/lib/IR/Verifier.cpp
  llvm/test/Verifier/noalias_scope_decl.ll


Index: llvm/test/Verifier/noalias_scope_decl.ll
===================================================================
--- llvm/test/Verifier/noalias_scope_decl.ll
+++ llvm/test/Verifier/noalias_scope_decl.ll
@@ -1,4 +1,7 @@
-; RUN: not llvm-as -disable-output --verify-noalias-scope-decl-dom < %s 2>&1 | FileCheck %s
+; RUN: not llvm-as -disable-output --verify-noalias-scope-decl-dom < %s 2>&1 | FileCheck %s --check-prefixes=CHECK,DOM
+; RUN: not llvm-as -disable-output --verify-noalias-scope-decl-dom --verify-noalias-scope-decl-dom-limit=100 < %s 2>&1 | FileCheck %s --check-prefixes=CHECK,DOM
+; RUN: not llvm-as -disable-output --verify-noalias-scope-decl-dom --verify-noalias-scope-decl-dom-limit=0 < %s 2>&1 | FileCheck %s --check-prefixes=CHECK,DOM
+; RUN: not llvm-as -disable-output --verify-noalias-scope-decl-dom --verify-noalias-scope-decl-dom-limit=1 < %s 2>&1 | FileCheck %s
 
 define void @test_single_scope01() nounwind ssp {
   tail call void @llvm.experimental.noalias.scope.decl(metadata !2)
@@ -30,16 +33,16 @@
   tail call void @llvm.experimental.noalias.scope.decl(metadata !6)
   ret void
 }
-; CHECK-NEXT: llvm.experimental.noalias.scope.decl dominates another one with the same scope
-; CHECK-NEXT:   tail call void @llvm.experimental.noalias.scope.decl(metadata !2)
+; DOM-NEXT: llvm.experimental.noalias.scope.decl dominates another one with the same scope
+; DOM-NEXT:   tail call void @llvm.experimental.noalias.scope.decl(metadata !2)
 
 define void @test_dom03() nounwind ssp {
   tail call void @llvm.experimental.noalias.scope.decl(metadata !2)
   tail call void @llvm.experimental.noalias.scope.decl(metadata !2)
   ret void
 }
-; CHECK-NEXT: llvm.experimental.noalias.scope.decl dominates another one with the same scope
-; CHECK-NEXT:   tail call void @llvm.experimental.noalias.scope.decl(metadata !2)
+; DOM-NEXT: llvm.experimental.noalias.scope.decl dominates another one with the same scope
+; DOM-NEXT:   tail call void @llvm.experimental.noalias.scope.decl(metadata !2)
 
 ; CHECK-NOT: llvm.experimental.noalias.scope.decl
 
Index: llvm/lib/IR/Verifier.cpp
===================================================================
--- llvm/lib/IR/Verifier.cpp
+++ llvm/lib/IR/Verifier.cpp
@@ -116,10 +116,23 @@
 using namespace llvm;
 
 static cl::opt<bool> VerifyNoAliasScopeDomination(
-    "verify-noalias-scope-decl-dom", cl::Hidden, cl::init(false),
+    "verify-noalias-scope-decl-dom", cl::Hidden, cl::init(true),
     cl::desc("Ensure that llvm.experimental.noalias.scope.decl for identical "
              "scopes are not dominating"));
 
+#ifdef EXPENSIVE_CHECKS
+#define VNASD_LIMIT 0
+#define VNASD_LIMIT_S "0"
+#else
+#define VNASD_LIMIT 1000
+#define VNASD_LIMIT_S "1000"
+#endif
+static cl::opt<unsigned> VerifyNoAliasScopeDominationLimit(
+    "verify-noalias-scope-decl-dom-limit", cl::Hidden, cl::init(VNASD_LIMIT),
+    cl::desc("Check the dominance relation only if there are at most N "
+             "llvm.experimental.noalias.scope.decl in the function. "
+             "(0 = always, default=" VNASD_LIMIT_S ")"));
+
 namespace llvm {
 
 struct VerifierSupport {
@@ -5560,6 +5573,11 @@
   if (!VerifyNoAliasScopeDomination)
     return;
 
+  // Avoid the worstcase O(N^2) behavior for large amounts of decls.
+  if (VerifyNoAliasScopeDominationLimit &&
+      NoAliasScopeDecls.size() > VerifyNoAliasScopeDominationLimit)
+    return;
+
   // Now sort the intrinsics based on the scope MDNode so that declarations of
   // the same scopes are next to each other.
   auto GetScope = [](IntrinsicInst *II) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D95335.318921.patch
Type: text/x-patch
Size: 3566 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210125/f88e88cf/attachment.bin>


More information about the llvm-commits mailing list