[llvm-commits] [llvm] r110382 - in /llvm/trunk: lib/Analysis/BasicAliasAnalysis.cpp lib/Analysis/MemoryDependenceAnalysis.cpp test/Analysis/BasicAA/getmodrefinfo-cs-cs.ll

Dan Gohman gohman at apple.com
Thu Aug 5 15:09:15 PDT 2010


Author: djg
Date: Thu Aug  5 17:09:15 2010
New Revision: 110382

URL: http://llvm.org/viewvc/llvm-project?rev=110382&view=rev
Log:
Fix memdep's code for reasoning about dependences between two calls. A Ref
response from getModRefInfo is not useful here. Instead, check for identical
calls only in the NoModRef case.

Reapply r110270, and strengthen it to compensate for the memdep changes.
When both calls are readonly, there is no dependence between them.

Modified:
    llvm/trunk/lib/Analysis/BasicAliasAnalysis.cpp
    llvm/trunk/lib/Analysis/MemoryDependenceAnalysis.cpp
    llvm/trunk/test/Analysis/BasicAA/getmodrefinfo-cs-cs.ll

Modified: llvm/trunk/lib/Analysis/BasicAliasAnalysis.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/BasicAliasAnalysis.cpp?rev=110382&r1=110381&r2=110382&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/BasicAliasAnalysis.cpp (original)
+++ llvm/trunk/lib/Analysis/BasicAliasAnalysis.cpp Thu Aug  5 17:09:15 2010
@@ -425,8 +425,13 @@
   ModRefBehavior CS2B = AliasAnalysis::getModRefBehavior(CS2);
   if (CS2B == DoesNotAccessMemory) return NoModRef;
   
-  // If they both only read from memory, just return ref.
+  // If they both only read from memory, there is no dependence.
   if (CS1B == OnlyReadsMemory && CS2B == OnlyReadsMemory)
+    return NoModRef;
+
+  // If CS1 only reads memory, the only dependence on CS2 can be
+  // from CS1 reading memory written by CS2.
+  if (CS1B == OnlyReadsMemory)
     return Ref;
   
   // Otherwise, fall back to NoAA (mod+ref).

Modified: llvm/trunk/lib/Analysis/MemoryDependenceAnalysis.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/MemoryDependenceAnalysis.cpp?rev=110382&r1=110381&r2=110382&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/MemoryDependenceAnalysis.cpp (original)
+++ llvm/trunk/lib/Analysis/MemoryDependenceAnalysis.cpp Thu Aug  5 17:09:15 2010
@@ -126,26 +126,15 @@
       // If these two calls do not interfere, look past it.
       switch (AA->getModRefInfo(CS, InstCS)) {
       case AliasAnalysis::NoModRef:
-        // If the two calls don't interact (e.g. InstCS is readnone) keep
-        // scanning.
+        // If the two calls are the same, return InstCS as a Def, so that
+        // CS can be found redundant and eliminated.
+        if (isReadOnlyCall && InstCS.onlyReadsMemory() &&
+            CS.getInstruction()->isIdenticalToWhenDefined(Inst))
+          return MemDepResult::getDef(Inst);
+
+        // Otherwise if the two calls don't interact (e.g. InstCS is readnone)
+        // keep scanning.
         continue;
-      case AliasAnalysis::Ref:
-        // If the two calls read the same memory locations and CS is a readonly
-        // function, then we have two cases: 1) the calls may not interfere with
-        // each other at all.  2) the calls may produce the same value.  In case
-        // #1 we want to ignore the values, in case #2, we want to return Inst
-        // as a Def dependence.  This allows us to CSE in cases like:
-        //   X = strlen(P);
-        //    memchr(...);
-        //   Y = strlen(P);  // Y = X
-        if (isReadOnlyCall) {
-          if (CS.getCalledFunction() != 0 &&
-              CS.getCalledFunction() == InstCS.getCalledFunction())
-            return MemDepResult::getDef(Inst);
-          // Ignore unrelated read/read call dependences.
-          continue;
-        }
-        // FALL THROUGH
       default:
         return MemDepResult::getClobber(Inst);
       }

Modified: llvm/trunk/test/Analysis/BasicAA/getmodrefinfo-cs-cs.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Analysis/BasicAA/getmodrefinfo-cs-cs.ll?rev=110382&r1=110381&r2=110382&view=diff
==============================================================================
--- llvm/trunk/test/Analysis/BasicAA/getmodrefinfo-cs-cs.ll (original)
+++ llvm/trunk/test/Analysis/BasicAA/getmodrefinfo-cs-cs.ll Thu Aug  5 17:09:15 2010
@@ -1,5 +1,4 @@
 ; RUN: opt < %s -aa-eval -print-all-alias-modref-info -disable-output |& FileCheck %s
-; XFAIL: *
 
 ; CHECK: Just Ref: call void @ro() <-> call void @f0()
 





More information about the llvm-commits mailing list