[llvm] r219122 - [CFL-AA] Update for handling of globals and more tests

Hal Finkel hfinkel at anl.gov
Mon Oct 6 07:42:56 PDT 2014


Author: hfinkel
Date: Mon Oct  6 09:42:56 2014
New Revision: 219122

URL: http://llvm.org/viewvc/llvm-project?rev=219122&view=rev
Log:
[CFL-AA] Update for handling of globals and more tests

We used to return PartialAlias if *either* variable being queried interacted
with arguments or globals. AFAICT, we can change this to only returning
MayAlias iff *both* variables being queried interacted with arguments or
globals.

Also, adding some basic functionality tests: some basic IPA tests, checking
that we give conservative responses with arguments/globals thrown in the mix,
and ensuring that we trace values through stores and loads.

Note that saying that 'x' interacted with arguments or globals means that the
Attributes of the StratifiedSet that 'x' belongs to has any bits set.

Patch by George Burgess IV, thanks!

Added:
    llvm/trunk/test/Analysis/CFLAliasAnalysis/arguments-globals.ll
    llvm/trunk/test/Analysis/CFLAliasAnalysis/arguments.ll
    llvm/trunk/test/Analysis/CFLAliasAnalysis/basic-interproc-ret.ll
    llvm/trunk/test/Analysis/CFLAliasAnalysis/basic-interproc.ll
    llvm/trunk/test/Analysis/CFLAliasAnalysis/multilevel-combine.ll
    llvm/trunk/test/Analysis/CFLAliasAnalysis/multilevel.ll
Modified:
    llvm/trunk/lib/Analysis/CFLAliasAnalysis.cpp

Modified: llvm/trunk/lib/Analysis/CFLAliasAnalysis.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/CFLAliasAnalysis.cpp?rev=219122&r1=219121&r2=219122&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/CFLAliasAnalysis.cpp (original)
+++ llvm/trunk/lib/Analysis/CFLAliasAnalysis.cpp Mon Oct  6 09:42:56 2014
@@ -986,9 +986,17 @@ CFLAliasAnalysis::query(const AliasAnaly
 
   auto AttrsA = Sets.getLink(SetA.Index).Attrs;
   auto AttrsB = Sets.getLink(SetB.Index).Attrs;
-  auto CombinedAttrs = AttrsA | AttrsB;
-  if (CombinedAttrs.any())
-    return AliasAnalysis::PartialAlias;
+  // Stratified set attributes are used as markets to signify whether a member
+  // of a StratifiedSet (or a member of a set above the current set) has 
+  // interacted with either arguments or globals. "Interacted with" meaning
+  // its value may be different depending on the value of an argument or 
+  // global. The thought behind this is that, because arguments and globals
+  // may alias each other, if AttrsA and AttrsB have touched args/globals,
+  // we must conservatively say that they alias. However, if at least one of 
+  // the sets has no values that could legally be altered by changing the value 
+  // of an argument or global, then we don't have to be as conservative.
+  if (AttrsA.any() && AttrsB.any())
+    return AliasAnalysis::MayAlias;
 
   return AliasAnalysis::NoAlias;
 }

Added: llvm/trunk/test/Analysis/CFLAliasAnalysis/arguments-globals.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Analysis/CFLAliasAnalysis/arguments-globals.ll?rev=219122&view=auto
==============================================================================
--- llvm/trunk/test/Analysis/CFLAliasAnalysis/arguments-globals.ll (added)
+++ llvm/trunk/test/Analysis/CFLAliasAnalysis/arguments-globals.ll Mon Oct  6 09:42:56 2014
@@ -0,0 +1,20 @@
+; This testcase ensures that CFL AA gives conservative answers on variables
+; that involve arguments.
+; (Everything should alias everything, because args can alias globals, so the
+; aliasing sets should of args+alloca+global should be combined)
+
+; RUN: opt < %s -cfl-aa -aa-eval -print-may-aliases -disable-output 2>&1 | FileCheck %s
+
+; CHECK:     Function: test
+
+ at g = external global i32
+
+define void @test(i1 %c, i32* %arg1, i32* %arg2) {
+  ; CHECK: 15 Total Alias Queries Performed
+  ; CHECK: 0 no alias responses
+  %A = alloca i32, align 4
+  %B = select i1 %c, i32* %arg1, i32* %arg2
+  %C = select i1 %c, i32* @g, i32* %A
+
+  ret void
+}

Added: llvm/trunk/test/Analysis/CFLAliasAnalysis/arguments.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Analysis/CFLAliasAnalysis/arguments.ll?rev=219122&view=auto
==============================================================================
--- llvm/trunk/test/Analysis/CFLAliasAnalysis/arguments.ll (added)
+++ llvm/trunk/test/Analysis/CFLAliasAnalysis/arguments.ll Mon Oct  6 09:42:56 2014
@@ -0,0 +1,15 @@
+; This testcase ensures that CFL AA gives conservative answers on variables
+; that involve arguments.
+
+; RUN: opt < %s -cfl-aa -aa-eval -print-may-aliases -disable-output 2>&1 | FileCheck %s
+
+; CHECK:     Function: test
+
+define void @test(i1 %c, i32* %arg1, i32* %arg2) {
+  ; CHECK: 6 Total Alias Queries Performed
+  ; CHECK: 3 no alias responses
+  %a = alloca i32, align 4
+  %b = select i1 %c, i32* %arg1, i32* %arg2
+
+  ret void
+}

Added: llvm/trunk/test/Analysis/CFLAliasAnalysis/basic-interproc-ret.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Analysis/CFLAliasAnalysis/basic-interproc-ret.ll?rev=219122&view=auto
==============================================================================
--- llvm/trunk/test/Analysis/CFLAliasAnalysis/basic-interproc-ret.ll (added)
+++ llvm/trunk/test/Analysis/CFLAliasAnalysis/basic-interproc-ret.ll Mon Oct  6 09:42:56 2014
@@ -0,0 +1,26 @@
+; This testcase ensures that CFL AA gives conservative answers on variables
+; that involve arguments.
+
+; RUN: opt < %s -cfl-aa -aa-eval -print-may-aliases -disable-output 2>&1 | FileCheck %s
+
+; CHECK:     Function: test
+; CHECK: 4 Total Alias Queries Performed
+; CHECK: 3 no alias responses
+; ^ The 1 MayAlias is due to %arg1. Sadly, we don't currently have machinery
+; in place to check whether %arg1 aliases %a, because BasicAA takes care of 
+; that for us.
+
+define i32* @test2(i32* %arg1) {
+  store i32 0, i32* %arg1
+
+  %a = alloca i32, align 4
+  ret i32* %a
+}
+
+define void @test() {
+  %a = alloca i32, align 4
+  %b = alloca i32, align 4
+  %c = call i32* @test2(i32* %a)
+
+  ret void
+}

Added: llvm/trunk/test/Analysis/CFLAliasAnalysis/basic-interproc.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Analysis/CFLAliasAnalysis/basic-interproc.ll?rev=219122&view=auto
==============================================================================
--- llvm/trunk/test/Analysis/CFLAliasAnalysis/basic-interproc.ll (added)
+++ llvm/trunk/test/Analysis/CFLAliasAnalysis/basic-interproc.ll Mon Oct  6 09:42:56 2014
@@ -0,0 +1,24 @@
+; This testcase ensures that CFL AA gives conservative answers on variables
+; that involve arguments.
+
+; RUN: opt < %s -cfl-aa -aa-eval -print-may-aliases -disable-output 2>&1 | FileCheck %s
+
+; CHECK:     Function: test
+; CHECK: 2 Total Alias Queries Performed
+; CHECK: 1 no alias responses
+; ^^ In @test2, %arg1 and %arg2 may alias
+
+define void @test2(i32* %arg1, i32* %arg2) {
+  store i32 0, i32* %arg1
+  store i32 0, i32* %arg2
+
+  ret void
+}
+
+define void @test() {
+  %a = alloca i32, align 4
+  %b = alloca i32, align 4
+  call void @test2(i32* %a, i32* %b)
+
+  ret void
+}

Added: llvm/trunk/test/Analysis/CFLAliasAnalysis/multilevel-combine.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Analysis/CFLAliasAnalysis/multilevel-combine.ll?rev=219122&view=auto
==============================================================================
--- llvm/trunk/test/Analysis/CFLAliasAnalysis/multilevel-combine.ll (added)
+++ llvm/trunk/test/Analysis/CFLAliasAnalysis/multilevel-combine.ll Mon Oct  6 09:42:56 2014
@@ -0,0 +1,31 @@
+; This testcase ensures that CFL AA responds conservatively when we union 
+; groups of pointers together through ternary/conditional operations
+; Derived from:
+; void foo(bool c) {
+;   char a, b;
+;   char *m = c ? &a : &b;
+;   *m;
+; }
+;
+
+; RUN: opt < %s -cfl-aa -aa-eval -print-may-aliases -disable-output 2>&1 | FileCheck %s
+
+%T = type { i32, [10 x i8] }
+
+; CHECK:     Function: test
+
+define void @test(i1 %C) {
+; CHECK: 10 Total Alias Queries Performed
+; CHECK: 4 no alias responses
+  %M = alloca %T*, align 8 ; NoAlias with %A, %B, %MS, %AP
+  %A = alloca %T, align 8
+  %B = alloca %T, align 8
+
+  %MS = select i1 %C, %T* %B, %T* %A
+
+  store %T* %MS, %T** %M
+
+  %AP = load %T** %M ; PartialAlias with %A, %B
+
+  ret void
+}

Added: llvm/trunk/test/Analysis/CFLAliasAnalysis/multilevel.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Analysis/CFLAliasAnalysis/multilevel.ll?rev=219122&view=auto
==============================================================================
--- llvm/trunk/test/Analysis/CFLAliasAnalysis/multilevel.ll (added)
+++ llvm/trunk/test/Analysis/CFLAliasAnalysis/multilevel.ll Mon Oct  6 09:42:56 2014
@@ -0,0 +1,30 @@
+; This testcase ensures that CFL AA handles trivial cases with storing 
+; pointers in pointers appropriately.
+; Derived from:
+; char a, b;
+; char *m = &a, *n = &b;
+; *m;
+; *n;
+
+; RUN: opt < %s -cfl-aa -aa-eval -print-may-aliases -disable-output 2>&1 | FileCheck %s
+
+%T = type { i32, [10 x i8] }
+
+; CHECK:     Function: test
+
+define void @test() {
+; CHECK: 15 Total Alias Queries Performed
+; CHECK: 13 no alias responses
+  %M = alloca %T*, align 8
+  %N = alloca %T*, align 8
+  %A = alloca %T, align 8
+  %B = alloca %T, align 8
+
+  store %T* %A, %T** %M
+  store %T* %B, %T** %N
+
+  %AP = load %T** %M ; PartialAlias with %A
+  %BP = load %T** %N ; PartialAlias with %B
+
+  ret void
+}





More information about the llvm-commits mailing list