Fix a bug in non-local memdep that was causing an infinite loop on 175.vpr.
authorOwen Anderson <resistor@mac.com>
Wed, 25 Jul 2007 21:26:36 +0000 (21:26 +0000)
committerOwen Anderson <resistor@mac.com>
Wed, 25 Jul 2007 21:26:36 +0000 (21:26 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@40495 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Analysis/MemoryDependenceAnalysis.cpp
test/Transforms/GVN/2007-07-25-Loop.ll [new file with mode: 0644]

index ae26c26dad0329b361178c883b1e67a4ac92f80a..e260b271641e45d05412e233cb1a66bea088b83a 100644 (file)
@@ -103,7 +103,8 @@ Instruction* MemoryDependenceAnalysis::getCallSiteDependency(CallSite C, Instruc
 
 bool MemoryDependenceAnalysis::nonLocalHelper(Instruction* query,
                                               BasicBlock* block,
-                                              DenseMap<BasicBlock*, Value*>& resp) {
+                                              DenseMap<BasicBlock*, Value*>& resp,
+                                              SmallPtrSet<BasicBlock*, 4>& visited) {
   if (resp.count(block))
     return resp[block] != None;
   
@@ -113,10 +114,15 @@ bool MemoryDependenceAnalysis::nonLocalHelper(Instruction* query,
     return true;
   }
   
+  visited.insert(block);
+  
   bool inserted = false;
   for (pred_iterator PI = pred_begin(block), PE = pred_end(block);
        PI != PE; ++PI)
-    inserted |= nonLocalHelper(query, *PI, resp);
+    if (!visited.count(*PI))
+      inserted |= nonLocalHelper(query, *PI, resp, visited);
+  
+  visited.erase(block);
   
   if (!inserted)
     resp.insert(std::make_pair(block, None));
@@ -133,11 +139,14 @@ bool MemoryDependenceAnalysis::getNonLocalDependency(Instruction* query,
   }
   
   bool inserted = false;
+  SmallPtrSet<BasicBlock*, 4> visited;
+  visited.insert(query->getParent());
   
   BasicBlock* parent = query->getParent();
   for (pred_iterator PI = pred_begin(parent), PE = pred_end(parent);
        PI != PE; ++PI) {
-    inserted |= nonLocalHelper(query, *PI, resp);
+    if (!visited.count(*PI))
+      inserted |= nonLocalHelper(query, *PI, resp, visited);
   }
   
   if (!inserted)
diff --git a/test/Transforms/GVN/2007-07-25-Loop.ll b/test/Transforms/GVN/2007-07-25-Loop.ll
new file mode 100644 (file)
index 0000000..2efacb5
--- /dev/null
@@ -0,0 +1,15 @@
+; RUN: llvm-as < %s | opt -gvn | llvm-dis
+
+       %struct.s_segment_inf = type { float, i32, i16, i16, float, float, i32, float, float }
+
+define void @print_arch(i8* %arch_file, i32 %route_type, i64 %det_routing_arch.0.0, i64 %det_routing_arch.0.1, i64 %det_routing_arch.0.2, i64 %det_routing_arch.0.3, i64 %det_routing_arch.0.4, %struct.s_segment_inf* %segment_inf, i64 %timing_inf.0.0, i64 %timing_inf.0.1, i64 %timing_inf.0.2, i64 %timing_inf.0.3, i64 %timing_inf.0.4, i32 %timing_inf.1) {
+entry:
+       br i1 false, label %bb278, label %bb344
+
+bb278:         ; preds = %bb278, %entry
+       br i1 false, label %bb278, label %bb344
+
+bb344:         ; preds = %bb278, %entry
+       %tmp38758 = load i16* null, align 2             ; <i16> [#uses=0]
+       ret void
+}