This is an archive of the discontinued LLVM Phabricator instance.

Introduce -enable-global-analyses to allow users to disable inter-procedural analyses
ClosedPublic

Authored by nlopes on Sep 18 2022, 9:13 AM.

Details

Summary

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
}

Diff Detail

Event Timeline

nlopes created this revision.Sep 18 2022, 9:13 AM
Herald added a project: Restricted Project. · View Herald TranscriptSep 18 2022, 9:13 AM
nlopes requested review of this revision.Sep 18 2022, 9:13 AM
Herald added a project: Restricted Project. · View Herald TranscriptSep 18 2022, 9:13 AM
nlopes edited the summary of this revision. (Show Details)Sep 18 2022, 9:13 AM
nikic accepted this revision.Sep 19 2022, 3:55 AM

LGTM

llvm/lib/Passes/PassBuilderPipelines.cpp
189

Make the var name EnableGlobalAnalyses to match the option name?

This revision is now accepted and ready to land.Sep 19 2022, 3:55 AM
This revision was landed with ongoing or failed builds.Sep 19 2022, 4:00 AM
This revision was automatically updated to reflect the committed changes.
fhahn added a comment.Sep 19 2022, 4:10 AM

Could you also add a test for the option?