summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2011-02-28 07:16:14 +0000
committerChris Lattner <sabre@nondot.org>2011-02-28 07:16:14 +0000
commit62208c395a92cdef1a6a4fb242f7ea155abf142e (patch)
treefd5f0f2c518be7289eb740c9982920c4be5e01f8
parent29dbbd12c17e8f87ba95dc9bdbf2cad7ed6e88d3 (diff)
downloadbcm5719-llvm-62208c395a92cdef1a6a4fb242f7ea155abf142e.tar.gz
bcm5719-llvm-62208c395a92cdef1a6a4fb242f7ea155abf142e.zip
make switch constant folding a bit stronger, handling a missed case.
llvm-svn: 126638
-rw-r--r--clang/lib/CodeGen/CGStmt.cpp11
-rw-r--r--clang/test/CodeGen/switch-dce.c18
2 files changed, 25 insertions, 4 deletions
diff --git a/clang/lib/CodeGen/CGStmt.cpp b/clang/lib/CodeGen/CGStmt.cpp
index c67d1d1b0da..21fb36a72d6 100644
--- a/clang/lib/CodeGen/CGStmt.cpp
+++ b/clang/lib/CodeGen/CGStmt.cpp
@@ -895,9 +895,14 @@ static CSFC_Result CollectStatementsForCase(const Stmt *S,
case CSFC_Success:
// A successful result means that either 1) that the statement doesn't
// have the case and is skippable, or 2) does contain the case value
- // and also contains the break to exit the switch. In either case,
- // we continue scanning the body of the compound statement to see if
- // the rest are skippable or have the case.
+ // and also contains the break to exit the switch. In the later case,
+ // we just verify the rest of the statements are elidable.
+ if (FoundCase) {
+ for (++I; I != E; ++I)
+ if (CodeGenFunction::ContainsLabel(*I, true))
+ return CSFC_Failure;
+ return CSFC_Success;
+ }
break;
case CSFC_FallThrough:
// If we have a fallthrough condition, then we must have found the
diff --git a/clang/test/CodeGen/switch-dce.c b/clang/test/CodeGen/switch-dce.c
index 95c5e03633a..82b206149b9 100644
--- a/clang/test/CodeGen/switch-dce.c
+++ b/clang/test/CodeGen/switch-dce.c
@@ -167,7 +167,9 @@ void test9(int i) {
}
}
-
+// CHECK: @test10
+// CHECK-NOT: switch
+// CHECK: ret i32
int test10(void) {
switch(8) {
case 8:
@@ -180,3 +182,17 @@ int test10(void) {
return 0;
}
+
+// CHECK: @test11
+// CHECK-NOT: switch
+// CHECK: ret void
+void test11() {
+ switch (1) {
+ case 1:
+ break;
+ case 42: ;
+ int x; // eliding var decl?
+ x = 4;
+ break;
+ }
+}
OpenPOWER on IntegriCloud