[llvm-commits] [llvm] r137755 - in /llvm/trunk: lib/Transforms/Scalar/SCCP.cpp test/Transforms/SCCP/switch.ll

Eli Friedman eli.friedman at gmail.com
Tue Aug 16 14:12:35 PDT 2011


Author: efriedma
Date: Tue Aug 16 16:12:35 2011
New Revision: 137755

URL: http://llvm.org/viewvc/llvm-project?rev=137755&view=rev
Log:
Minor bug in SCCP found by inspection.  (I don't think it's possible to hit this with a normal pass pipeline, but fixing for completeness.)


Added:
    llvm/trunk/test/Transforms/SCCP/switch.ll
Modified:
    llvm/trunk/lib/Transforms/Scalar/SCCP.cpp

Modified: llvm/trunk/lib/Transforms/Scalar/SCCP.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/SCCP.cpp?rev=137755&r1=137754&r2=137755&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/SCCP.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/SCCP.cpp Tue Aug 16 16:12:35 2011
@@ -582,6 +582,10 @@
   }
   
   if (SwitchInst *SI = dyn_cast<SwitchInst>(&TI)) {
+    if (TI.getNumSuccessors() < 2) {
+      Succs[0] = true;
+      return;
+    }
     LatticeVal SCValue = getValueState(SI->getCondition());
     ConstantInt *CI = SCValue.getConstantInt();
     
@@ -642,6 +646,9 @@
     return true;
   
   if (SwitchInst *SI = dyn_cast<SwitchInst>(TI)) {
+    if (SI->getNumSuccessors() < 2)
+      return true;
+
     LatticeVal SCValue = getValueState(SI->getCondition());
     ConstantInt *CI = SCValue.getConstantInt();
     

Added: llvm/trunk/test/Transforms/SCCP/switch.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/SCCP/switch.ll?rev=137755&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/SCCP/switch.ll (added)
+++ llvm/trunk/test/Transforms/SCCP/switch.ll Tue Aug 16 16:12:35 2011
@@ -0,0 +1,13 @@
+; RUN: opt -S -sccp < %s | FileCheck %s
+
+; Make sure we always consider the default edge executable for a switch
+; with no cases.
+declare void @foo()
+define void @test1() {
+; CHECK: define void @test1
+; CHECK: call void @foo()
+  switch i32 undef, label %d []
+d:
+  call void @foo()
+  ret void
+}





More information about the llvm-commits mailing list