[llvm-commits] [llvm] r120368 - in /llvm/trunk: lib/Analysis/BasicAliasAnalysis.cpp lib/Transforms/Scalar/DeadStoreElimination.cpp test/Transforms/DeadStoreElimination/simple.ll

Chris Lattner sabre at nondot.org
Mon Nov 29 16:28:45 PST 2010


Author: lattner
Date: Mon Nov 29 18:28:45 2010
New Revision: 120368

URL: http://llvm.org/viewvc/llvm-project?rev=120368&view=rev
Log:
Teach basicaa that memset's modref set is at worst "mod" and never
contains "ref".

Enhance DSE to use a modref query instead of a store-specific hack
to generalize the "ignore may-alias stores" optimization to handle
memset and memcpy.

Modified:
    llvm/trunk/lib/Analysis/BasicAliasAnalysis.cpp
    llvm/trunk/lib/Transforms/Scalar/DeadStoreElimination.cpp
    llvm/trunk/test/Transforms/DeadStoreElimination/simple.ll

Modified: llvm/trunk/lib/Analysis/BasicAliasAnalysis.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/BasicAliasAnalysis.cpp?rev=120368&r1=120367&r2=120368&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/BasicAliasAnalysis.cpp (original)
+++ llvm/trunk/lib/Analysis/BasicAliasAnalysis.cpp Mon Nov 29 18:28:45 2010
@@ -703,6 +703,8 @@
         if (isNoAlias(Location(Dest, Len), Loc))
           return NoModRef;
       }
+      // We know that memset doesn't load anything.
+      Min = Mod;
       break;
     case Intrinsic::atomic_cmp_swap:
     case Intrinsic::atomic_swap:

Modified: llvm/trunk/lib/Transforms/Scalar/DeadStoreElimination.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/DeadStoreElimination.cpp?rev=120368&r1=120367&r2=120368&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/DeadStoreElimination.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/DeadStoreElimination.cpp Mon Nov 29 18:28:45 2010
@@ -191,6 +191,7 @@
          I1Size >= I2Size;
 }
 
+
 bool DSE::runOnBasicBlock(BasicBlock &BB) {
   MemoryDependenceAnalysis &MD = getAnalysis<MemoryDependenceAnalysis>();
   TD = getAnalysisIfAvailable<TargetData>();
@@ -239,7 +240,7 @@
         }
       }
     }
-     
+
     if (!InstDep.isDef()) {
       // If this is a may-aliased store that is clobbering the store value, we
       // can keep searching past it for another must-aliased pointer that stores
@@ -250,12 +251,16 @@
       // we can remove the first store to P even though we don't know if P and Q
       // alias.
       if (StoreInst *SI = dyn_cast<StoreInst>(Inst)) {
-        AliasAnalysis::Location Loc =
-          getAnalysis<AliasAnalysis>().getLocation(SI);
-        while (InstDep.isClobber() && isa<StoreInst>(InstDep.getInst()) &&
-               InstDep.getInst() != &BB.front())
-          InstDep = MD.getPointerDependencyFrom(Loc, false, InstDep.getInst(),
-                                                &BB);
+        AliasAnalysis &AA = getAnalysis<AliasAnalysis>();
+        AliasAnalysis::Location Loc = AA.getLocation(SI);
+        while (InstDep.isClobber() && InstDep.getInst() != &BB.front()) {
+          // Can't look past this instruction if it might read 'Loc'.
+          if (AA.getModRefInfo(InstDep.getInst(), Loc) & AliasAnalysis::Ref)
+            break;
+          
+          InstDep = MD.getPointerDependencyFrom(Loc, false,
+                                                InstDep.getInst(), &BB);
+        }
       }
     }
     

Modified: llvm/trunk/test/Transforms/DeadStoreElimination/simple.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/DeadStoreElimination/simple.ll?rev=120368&r1=120367&r2=120368&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/DeadStoreElimination/simple.ll (original)
+++ llvm/trunk/test/Transforms/DeadStoreElimination/simple.ll Mon Nov 29 18:28:45 2010
@@ -54,3 +54,17 @@
 ; CHECK-NEXT: volatile load
 ; CHECK-NEXT: ret void
 }
+
+declare void @llvm.memset.i32(i8*, i8, i32, i32)
+
+; Should delete store of 10 even though memset is a may-store to P (P and Q may
+; alias).
+define void @test6(i32 *%p, i8 *%q) {
+  store i32 10, i32* %p, align 4       ;; dead.
+  call void @llvm.memset.i32(i8* %q, i8 42, i32 900, i32 1)
+  store i32 30, i32* %p, align 4
+  ret void
+; CHECK: @test6
+; CHECK-NEXT: call void @llvm.memset
+}
+





More information about the llvm-commits mailing list