Cleanup/remove some parts of the lifetime region handling code in memdep and GVN,
authorOwen Anderson <resistor@mac.com>
Wed, 2 Dec 2009 07:35:19 +0000 (07:35 +0000)
committerOwen Anderson <resistor@mac.com>
Wed, 2 Dec 2009 07:35:19 +0000 (07:35 +0000)
per Chris' comments.  Adjust testcases to match.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@90304 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Analysis/MemoryDependenceAnalysis.cpp
lib/Transforms/Scalar/GVN.cpp
test/Transforms/DeadStoreElimination/lifetime-simple.ll [deleted file]
test/Transforms/GVN/lifetime-simple.ll

index f4531e09579b70f6c2e2d5aa7e01514491ffcde4..60fe15fe52ea086a364f1660bb45a365a8e2af85 100644 (file)
@@ -186,15 +186,17 @@ getPointerDependencyFrom(Value *MemPtr, uint64_t MemSize, bool isLoad,
     }
     
     if (IntrinsicInst *II = dyn_cast<IntrinsicInst>(Inst)) {
     }
     
     if (IntrinsicInst *II = dyn_cast<IntrinsicInst>(Inst)) {
+      // Debug intrinsics don't cause dependences.
+      if (isa<DbgInfoIntrinsic>(Inst)) continue;
+      
       // If we pass an invariant-end marker, then we've just entered an
       // invariant region and can start ignoring dependencies.
       if (II->getIntrinsicID() == Intrinsic::invariant_end) {
       // If we pass an invariant-end marker, then we've just entered an
       // invariant region and can start ignoring dependencies.
       if (II->getIntrinsicID() == Intrinsic::invariant_end) {
-        uint64_t InvariantSize = ~0ULL;
-        if (ConstantInt *CI = dyn_cast<ConstantInt>(II->getOperand(2)))
-          InvariantSize = CI->getZExtValue();
-        
-        AliasAnalysis::AliasResult R =
-          AA->alias(II->getOperand(3), InvariantSize, MemPtr, MemSize);
+        // FIXME: This only considers queries directly on the invariant-tagged
+        // pointer, not on query pointers that are indexed off of them.  It'd
+        // be nice to handle that at some point.
+        AliasAnalysis::AliasResult R = 
+          AA->alias(II->getOperand(3), ~0ULL, MemPtr, ~0ULL);
         if (R == AliasAnalysis::MustAlias) {
           InvariantTag = II->getOperand(1);
           continue;
         if (R == AliasAnalysis::MustAlias) {
           InvariantTag = II->getOperand(1);
           continue;
@@ -202,14 +204,12 @@ getPointerDependencyFrom(Value *MemPtr, uint64_t MemSize, bool isLoad,
       
       // If we reach a lifetime begin or end marker, then the query ends here
       // because the value is undefined.
       
       // If we reach a lifetime begin or end marker, then the query ends here
       // because the value is undefined.
-      } else if (II->getIntrinsicID() == Intrinsic::lifetime_start ||
-                 II->getIntrinsicID() == Intrinsic::lifetime_end) {
-        uint64_t InvariantSize = ~0ULL;
-        if (ConstantInt *CI = dyn_cast<ConstantInt>(II->getOperand(1)))
-          InvariantSize = CI->getZExtValue();
-
+      } else if (II->getIntrinsicID() == Intrinsic::lifetime_start) {
+        // FIXME: This only considers queries directly on the invariant-tagged
+        // pointer, not on query pointers that are indexed off of them.  It'd
+        // be nice to handle that at some point.
         AliasAnalysis::AliasResult R =
         AliasAnalysis::AliasResult R =
-          AA->alias(II->getOperand(2), InvariantSize, MemPtr, MemSize);
+          AA->alias(II->getOperand(2), ~0ULL, MemPtr, ~0ULL);
         if (R == AliasAnalysis::MustAlias)
           return MemDepResult::getDef(II);
       }
         if (R == AliasAnalysis::MustAlias)
           return MemDepResult::getDef(II);
       }
@@ -219,9 +219,6 @@ getPointerDependencyFrom(Value *MemPtr, uint64_t MemSize, bool isLoad,
     // at this point. Nothing a load depends on can live in an invariant region.
     if (isLoad && InvariantTag) continue;
 
     // at this point. Nothing a load depends on can live in an invariant region.
     if (isLoad && InvariantTag) continue;
 
-    // Debug intrinsics don't cause dependences.
-    if (isa<DbgInfoIntrinsic>(Inst)) continue;
-
     // Values depend on loads if the pointers are must aliased.  This means that
     // a load depends on another must aliased load from the same value.
     if (LoadInst *LI = dyn_cast<LoadInst>(Inst)) {
     // Values depend on loads if the pointers are must aliased.  This means that
     // a load depends on another must aliased load from the same value.
     if (LoadInst *LI = dyn_cast<LoadInst>(Inst)) {
index 1b42c6b9592bb550c85875ff304af2c968d92ac0..ceb57f85a5fae34f396cea3b0aae49de71ee087e 100644 (file)
@@ -1187,10 +1187,9 @@ static Value *ConstructSSAForLoadSet(LoadInst *LI,
   return V;
 }
 
   return V;
 }
 
-static bool isLifetimeStartOrEnd(Instruction *Inst) {
+static bool isLifetimeStart(Instruction *Inst) {
   if (IntrinsicInst* II = dyn_cast<IntrinsicInst>(Inst))
   if (IntrinsicInst* II = dyn_cast<IntrinsicInst>(Inst))
-    return II->getIntrinsicID() == Intrinsic::lifetime_start ||
-           II->getIntrinsicID() == Intrinsic::lifetime_end;
+    return II->getIntrinsicID() == Intrinsic::lifetime_start;
   return false;
 }
 
   return false;
 }
 
@@ -1262,8 +1261,8 @@ bool GVN::processNonLocalLoad(LoadInst *LI,
 
     // Loading the allocation -> undef.
     if (isa<AllocaInst>(DepInst) || isMalloc(DepInst) ||
 
     // Loading the allocation -> undef.
     if (isa<AllocaInst>(DepInst) || isMalloc(DepInst) ||
-        // Loading immediately after lifetime begin or end -> undef.
-        isLifetimeStartOrEnd(DepInst)) {
+        // Loading immediately after lifetime begin -> undef.
+        isLifetimeStart(DepInst)) {
       ValuesPerBlock.push_back(AvailableValueInBlock::get(DepBB,
                                              UndefValue::get(LI->getType())));
       continue;
       ValuesPerBlock.push_back(AvailableValueInBlock::get(DepBB,
                                              UndefValue::get(LI->getType())));
       continue;
@@ -1635,11 +1634,10 @@ bool GVN::processLoad(LoadInst *L, SmallVectorImpl<Instruction*> &toErase) {
     return true;
   }
   
     return true;
   }
   
-  // If this load occurs either right after a lifetime begin or a lifetime end,
+  // If this load occurs either right after a lifetime begin,
   // then the loaded value is undefined.
   if (IntrinsicInst* II = dyn_cast<IntrinsicInst>(DepInst)) {
   // then the loaded value is undefined.
   if (IntrinsicInst* II = dyn_cast<IntrinsicInst>(DepInst)) {
-    if (II->getIntrinsicID() == Intrinsic::lifetime_start ||
-        II->getIntrinsicID() == Intrinsic::lifetime_end) {
+    if (II->getIntrinsicID() == Intrinsic::lifetime_start) {
       L->replaceAllUsesWith(UndefValue::get(L->getType()));
       toErase.push_back(L);
       NumGVNLoad++;
       L->replaceAllUsesWith(UndefValue::get(L->getType()));
       toErase.push_back(L);
       NumGVNLoad++;
diff --git a/test/Transforms/DeadStoreElimination/lifetime-simple.ll b/test/Transforms/DeadStoreElimination/lifetime-simple.ll
deleted file mode 100644 (file)
index 430e700..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-; RUN: opt < %s -dse -S | FileCheck %s
-
-target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128"
-target triple = "i386-apple-darwin7"
-
-define i8 @test2(i8* %P) nounwind {
-; CHECK: @test2
-; CHECK-NOT: store i8 1
-; CHECK: ret i8 0
-entry:
-  call void @llvm.lifetime.start(i64 32, i8* %P)
-  call void @llvm.lifetime.end(i64 32, i8* %P)
-  store i8 1, i8* %P
-  ret i8 0
-}
-
-declare {}* @llvm.lifetime.start(i64 %S, i8* nocapture %P) readonly
-declare void @llvm.lifetime.end(i64 %S, i8* nocapture %P)
\ No newline at end of file
index 00a0c2907c16fb31fc084192fcdbcf0d3fbf03cb..8139246dcf3c8bab9a075588e352b737a7731068 100644 (file)
@@ -4,9 +4,9 @@ target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f3
 target triple = "i386-apple-darwin7"
 
 define i8 @test(i8* %P) nounwind {
 target triple = "i386-apple-darwin7"
 
 define i8 @test(i8* %P) nounwind {
-; CHECK: @test
+; CHECK: lifetime.start
 ; CHECK-NOT: load
 ; CHECK-NOT: load
-; CHECK: ret i8 undef
+; CHECK: lifetime.end
 entry:
   call void @llvm.lifetime.start(i64 32, i8* %P)
   %0 = load i8* %P
 entry:
   call void @llvm.lifetime.start(i64 32, i8* %P)
   %0 = load i8* %P