[PATCH] Improve BasicAA Pass Using zext Information

hfinkel at anl.gov hfinkel at anl.gov
Mon Sep 29 11:06:15 PDT 2014


================
Comment at: lib/Analysis/BasicAliasAnalysis.cpp:1242
@@ +1241,3 @@
+  //   %idx = getelementptr inbounds i32* %memory, i64 %i
+  //   %i.plus1 = add nsw nuw i64 %i, 1
+  //   store i64 %i.plus1, i64* %somewhere
----------------
As you've written the example, %phi and %idx don't alias, because %idx == %phi+1. If you take out the add and store the original value (or don't update*%somewhere at all), then they will alias.

================
Comment at: lib/Analysis/BasicAliasAnalysis.cpp:1247
@@ +1246,3 @@
+  // In the loop body, %idx trivially MustAlias to %idx, however we can see
+  // that %phi is NoAlias to %idx. This is because %phi is %idx from a previous
+  // iteration of the loop, and after we calculated %idx we used a 'store' to
----------------
When you see "we can see that", you mean that without this check we'd return NoAlias, right? That does not seem right. Without this patch (current trunk), if I take this function:

  define void @test1(i64* noalias %somewhere, i32* noalias %memory) {
  entry:
    br label %for.body

  for.body:
     %phi = phi i32* [%idx, %for.body], [null, %entry]
     %i = load i64* %somewhere
     %idx = getelementptr inbounds i32* %memory, i64 %i
     %i.plus1 = add nsw nuw i64 %i, 1
     store i64 %i.plus1, i64* %somewhere
     br label %for.body
  }

and run it through:
  opt < -basicaa -aa-eval -print-all-alias-modref-info -disable-output

I get:

  Function: test1: 4 pointers, 0 call sites
    NoAlias:      i32* %memory, i64* %somewhere
    NoAlias:      i32* %phi, i64* %somewhere
    MayAlias:     i32* %memory, i32* %phi
    NoAlias:      i32* %idx, i64* %somewhere
    PartialAlias: i32* %idx, i32* %memory
    MayAlias:     i32* %idx, i32* %phi

which already gives "MayAlias:     i32* %idx, i32* %phi".

In short, I'm still not entirely sure I understand the problem you're trying to fix here.

================
Comment at: lib/Analysis/BasicAliasAnalysis.cpp:1256
@@ +1255,3 @@
+    //
+    // TODO: this could be tightened to any loop where Inst, or any of the
+    // (transitive) Instructions that generated Inst returns true for
----------------
What do you mean by "tightened" here?

================
Comment at: lib/Analysis/BasicAliasAnalysis.cpp:1259
@@ +1258,3 @@
+    // Instruction::mayReadFromMemory
+    if(Inst 
+    && isPotentiallyReachable(PN, Inst, DT, LI)
----------------
Space after the if.

http://reviews.llvm.org/D5514






More information about the llvm-commits mailing list