[PATCH] D134139: Introduce -enable-global-analyses to allow users to disable inter-procedural analyses

Nuno Lopes via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Sep 18 09:13:09 PDT 2022


nlopes created this revision.
nlopes added reviewers: fhahn, nikic.
Herald added subscribers: bollu, hiraditya.
Herald added a project: All.
nlopes requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Alive2 doesn't support verification of optimizations that use inter-procedural analyses.
Right now, clang uses GlobalsAA by default and there's no way to disable it. This leads to Alive2 producing false positives.

Example:

file.c:
static int x;
int f() {

  x = 0;
  *p = 1;
  x = 2;
  return *p;

}

This file.c right now compiles to:
define i32 @f(ptr nocapture noundef %p) {

  store i32 1, ptr %p, align 4
  store i1 true, ptr @x, align 4
  ret i32 1

}

without globalsaa:
$ clang -S -emit-llvm -o - -O3 file.c -mllvm -enable-global-analyses=0

define i32 @f(ptr nocapture noundef %p) {

  store i32 1, ptr %p, align 4
  store i1 true, ptr @x, align 4
  %0 = load i32, ptr %p, align 4
  ret i32 %0

}


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D134139

Files:
  llvm/lib/Passes/PassBuilderPipelines.cpp


Index: llvm/lib/Passes/PassBuilderPipelines.cpp
===================================================================
--- llvm/lib/Passes/PassBuilderPipelines.cpp
+++ llvm/lib/Passes/PassBuilderPipelines.cpp
@@ -186,6 +186,10 @@
     "enable-post-pgo-loop-rotation", cl::init(true), cl::Hidden,
     cl::desc("Run the loop rotation transformation after PGO instrumentation"));
 
+static cl::opt<bool> EnableGlobalAnalysis(
+    "enable-global-analyses", cl::init(true), cl::Hidden,
+    cl::desc("Enable inter-procedural analyses"));
+
 PipelineTuningOptions::PipelineTuningOptions() {
   LoopInterleaving = true;
   LoopVectorization = true;
@@ -1898,7 +1902,8 @@
   // Because the `AAManager` is a function analysis and `GlobalsAA` is a module
   // analysis, all that the `AAManager` can do is query for any *cached*
   // results from `GlobalsAA` through a readonly proxy.
-  AA.registerModuleAnalysis<GlobalsAA>();
+  if (EnableGlobalAnalysis)
+    AA.registerModuleAnalysis<GlobalsAA>();
 
   // Add target-specific alias analyses.
   if (TM)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D134139.461079.patch
Type: text/x-patch
Size: 1047 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220918/a9dafb2d/attachment.bin>


More information about the llvm-commits mailing list