[cfe-commits] r126638 - in /cfe/trunk: lib/CodeGen/CGStmt.cpp test/CodeGen/switch-dce.c
Chris Lattner
sabre at nondot.org
Sun Feb 27 23:16:14 PST 2011
Author: lattner
Date: Mon Feb 28 01:16:14 2011
New Revision: 126638
URL: http://llvm.org/viewvc/llvm-project?rev=126638&view=rev
Log:
make switch constant folding a bit stronger, handling a missed case.
Modified:
cfe/trunk/lib/CodeGen/CGStmt.cpp
cfe/trunk/test/CodeGen/switch-dce.c
Modified: cfe/trunk/lib/CodeGen/CGStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGStmt.cpp?rev=126638&r1=126637&r2=126638&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGStmt.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGStmt.cpp Mon Feb 28 01:16:14 2011
@@ -895,9 +895,14 @@
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
Modified: cfe/trunk/test/CodeGen/switch-dce.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/switch-dce.c?rev=126638&r1=126637&r2=126638&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/switch-dce.c (original)
+++ cfe/trunk/test/CodeGen/switch-dce.c Mon Feb 28 01:16:14 2011
@@ -167,7 +167,9 @@
}
}
-
+// CHECK: @test10
+// CHECK-NOT: switch
+// CHECK: ret i32
int test10(void) {
switch(8) {
case 8:
@@ -180,3 +182,17 @@
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;
+ }
+}
More information about the cfe-commits
mailing list