diff options
| author | Chris Lattner <sabre@nondot.org> | 2011-02-28 00:22:07 +0000 |
|---|---|---|
| committer | Chris Lattner <sabre@nondot.org> | 2011-02-28 00:22:07 +0000 |
| commit | 0725a8b653ea4a7dedddfae6e65256dac8210dfd (patch) | |
| tree | 307ca2e2ae0728cb13e735d5ffb71d3b54260b6e /clang/test/CodeGen/switch-dce.c | |
| parent | 29911cc2f5cad4dcdca30656f79855e8c2acb333 (diff) | |
| download | bcm5719-llvm-0725a8b653ea4a7dedddfae6e65256dac8210dfd.tar.gz bcm5719-llvm-0725a8b653ea4a7dedddfae6e65256dac8210dfd.zip | |
First tiny step to implementing PR9322: build infrastructure for only emitting the
live case of a switch statement when switching on a constant. This is terribly
limited, but enough to handle the trivial example included. Before we would
emit:
define void @test1(i32 %i) nounwind {
entry:
%i.addr = alloca i32, align 4
store i32 %i, i32* %i.addr, align 4
switch i32 1, label %sw.epilog [
i32 1, label %sw.bb
]
sw.bb: ; preds = %entry
%tmp = load i32* %i.addr, align 4
%inc = add nsw i32 %tmp, 1
store i32 %inc, i32* %i.addr, align 4
br label %sw.epilog
sw.epilog: ; preds = %sw.bb, %entry
switch i32 0, label %sw.epilog3 [
i32 1, label %sw.bb1
]
sw.bb1: ; preds = %sw.epilog
%tmp2 = load i32* %i.addr, align 4
%add = add nsw i32 %tmp2, 2
store i32 %add, i32* %i.addr, align 4
br label %sw.epilog3
sw.epilog3: ; preds = %sw.bb1, %sw.epilog
ret void
}
now we emit:
define void @test1(i32 %i) nounwind {
entry:
%i.addr = alloca i32, align 4
store i32 %i, i32* %i.addr, align 4
%tmp = load i32* %i.addr, align 4
%inc = add nsw i32 %tmp, 1
store i32 %inc, i32* %i.addr, align 4
ret void
}
This improves -O0 compile time (less IR to generate and shove through the code
generator) and the clever linux kernel people found a way to fail to build if we
don't do this optimization. This step isn't enough to handle the kernel case
though.
llvm-svn: 126597
Diffstat (limited to 'clang/test/CodeGen/switch-dce.c')
| -rw-r--r-- | clang/test/CodeGen/switch-dce.c | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/clang/test/CodeGen/switch-dce.c b/clang/test/CodeGen/switch-dce.c new file mode 100644 index 00000000000..f06a3ed98c0 --- /dev/null +++ b/clang/test/CodeGen/switch-dce.c @@ -0,0 +1,18 @@ +// RUN: %clang_cc1 -triple i386-unknown-unknown -O0 %s -emit-llvm -o - | FileCheck %s + +// CHECK: @test1 +// CHECK-NOT: switch +// CHECK: add nsw i32 {{.*}}, 1 +// CHECK-NOT: switch +// CHECK-NOT: add nsw i32 +// CHECK: ret void +void test1() { + int i; + switch (1) + case 1: + ++i; + + switch (0) + case 1: + i+=2; +} |

