allow LazyValueInfo::getEdgeValue() to reason about multiple edges from the same...
authorNuno Lopes <nunoplopes@sapo.pt>
Fri, 18 May 2012 21:02:10 +0000 (21:02 +0000)
committerNuno Lopes <nunoplopes@sapo.pt>
Fri, 18 May 2012 21:02:10 +0000 (21:02 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@157071 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Analysis/LazyValueInfo.cpp
test/Transforms/CorrelatedValuePropagation/range.ll

index 83e021295bad041f293863d96a0e0093854b7eee..7539d93862d6f6d7423f8b0de329aea35b7b70f2 100644 (file)
@@ -862,21 +862,16 @@ bool LazyValueInfoCache::getEdgeValue(Value *Val, BasicBlock *BBFrom,
         return true;
       }
       
-      // We only know something if there is exactly one value that goes from
-      // BBFrom to BBTo.
-      unsigned NumEdges = 0;
-      ConstantInt *EdgeVal = 0;
+      unsigned BitWidth = Val->getType()->getIntegerBitWidth();
+      ConstantRange EdgesVals(BitWidth, false/*isFullSet*/);
       for (SwitchInst::CaseIt i = SI->case_begin(), e = SI->case_end();
            i != e; ++i) {
         if (i.getCaseSuccessor() != BBTo) continue;
-        if (NumEdges++) break;
-        EdgeVal = i.getCaseValue();
-      }
-      assert(EdgeVal && "Missing successor?");
-      if (NumEdges == 1) {
-        Result = LVILatticeVal::get(EdgeVal);
-        return true;
+        ConstantRange EdgeVal(i.getCaseValue()->getValue());
+        EdgesVals = EdgesVals.unionWith(EdgeVal);
       }
+      Result = LVILatticeVal::getRange(EdgesVals);
+      return true;
     }
   }
   
index 2bb21874ce15d2dc4cccd32f3cd24f6703107aff..4ac478b0d574e61d3ff72a558a8885ff0cd04182 100644 (file)
@@ -70,3 +70,31 @@ if.then4:
 if.end8:
   ret i32 4
 }
+
+; CHECK: @test4
+define i32 @test4(i32 %c) nounwind {
+  switch i32 %c, label %sw.default [
+    i32 1, label %sw.bb
+    i32 2, label %sw.bb
+    i32 4, label %sw.bb
+  ]
+
+; CHECK: sw.bb
+sw.bb:
+  %cmp = icmp sge i32 %c, 1
+; CHECK: br i1 true
+  br i1 %cmp, label %if.then, label %if.end
+
+if.then:
+  br label %return
+
+if.end:
+  br label %return
+
+sw.default:
+  br label %return
+
+return:
+  %retval.0 = phi i32 [ 42, %sw.default ], [ 4, %if.then ], [ 9, %if.end ]
+  ret i32 %retval.0
+}