SimplifyCFG: Turn switches into sub+icmp+branch if possible.

This makes the job of the later optzn passes easier, allowing the vast amount of
icmp transforms to chew on it.

We transform 840 switches in gcc.c, leading to a 16k byte shrink of the resulting
binary on i386-linux.

The testcase from README.txt now compiles into
  decl  %edi
  cmpl  $3, %edi
  sbbl  %eax, %eax
  andl  $1, %eax
  ret

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@124724 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Benjamin Kramer
2011-02-02 15:56:22 +00:00
parent ff0c5014b2
commit 56442dfdcf
4 changed files with 39 additions and 70 deletions

View File

@@ -141,14 +141,8 @@ UnifiedReturnBlock: ; preds = %shortcirc_done.4, %shortcirc_next.4
ret i1 %UnifiedRetVal
; CHECK: @test6
; CHECK: switch i32 %tmp.2.i, label %shortcirc_next.4 [
; CHECK: i32 14, label %UnifiedReturnBlock
; CHECK: i32 15, label %UnifiedReturnBlock
; CHECK: i32 16, label %UnifiedReturnBlock
; CHECK: i32 17, label %UnifiedReturnBlock
; CHECK: i32 18, label %UnifiedReturnBlock
; CHECK: i32 19, label %UnifiedReturnBlock
; CHECK: ]
; CHECK: %off = add i32 %tmp.2.i, -14
; CHECK: %switch = icmp ult i32 %off, 6
}
define void @test7(i8 zeroext %c, i32 %x) nounwind ssp noredzone {
@@ -447,11 +441,8 @@ if.end:
define zeroext i1 @test16(i32 %x) nounwind {
entry:
; CHECK: @test16
; CHECK: switch i32 %x, label %lor.rhs [
; CHECK: i32 1, label %lor.end
; CHECK: i32 2, label %lor.end
; CHECK: i32 3, label %lor.end
; CHECK: ]
; CHECK: %off = add i32 %x, -1
; CHECK: %switch = icmp ult i32 %off, 3
%cmp.i = icmp eq i32 %x, 1
br i1 %cmp.i, label %lor.end, label %lor.lhs.false

View File

@@ -13,15 +13,9 @@
declare void @llvm.dbg.stoppoint(i32, i32, { }*) nounwind
define i1 @t({ i32, i32 }* %I) {
; CHECK: t
; CHECK: switch i32 %tmp.2.i, label %shortcirc_next.4 [
; CHECK: i32 14, label %UnifiedReturnBlock
; CHECK: i32 15, label %UnifiedReturnBlock
; CHECK: i32 16, label %UnifiedReturnBlock
; CHECK: i32 17, label %UnifiedReturnBlock
; CHECK: i32 18, label %UnifiedReturnBlock
; CHECK: i32 19, label %UnifiedReturnBlock
; CHECK: ]
; CHECK: @t
; CHECK: %off = add i32 %tmp.2.i, -14
; CHECK: %switch = icmp ult i32 %off, 6
entry:
%tmp.1.i = getelementptr { i32, i32 }* %I, i64 0, i32 1 ; <i32*> [#uses=1]
%tmp.2.i = load i32* %tmp.1.i ; <i32> [#uses=6]