• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1; RUN: opt < %s -simplifycfg -S | FileCheck %s
2
3; Test that a switch going to a switch on the same value can be merged.
4; All three switches in this example can be merged into one big one.
5
6declare void @foo1()
7
8declare void @foo2()
9
10declare void @foo3()
11
12declare void @foo4()
13
14define void @test1(i32 %V) {
15        switch i32 %V, label %F [
16                 i32 4, label %T
17                 i32 17, label %T
18                 i32 5, label %T
19                 i32 1234, label %F
20        ]
21T:              ; preds = %0, %0, %0
22        switch i32 %V, label %F [
23                 i32 4, label %A
24                 i32 17, label %B
25                 i32 42, label %C
26        ]
27A:              ; preds = %T
28        call void @foo1( )
29        ret void
30B:              ; preds = %F, %F, %T
31        call void @foo2( )
32        ret void
33C:              ; preds = %T
34        call void @foo3( )
35        ret void
36F:              ; preds = %F, %T, %0, %0
37        switch i32 %V, label %F [
38                 i32 4, label %B
39                 i32 18, label %B
40                 i32 42, label %D
41        ]
42D:              ; preds = %F
43        call void @foo4( )
44        ret void
45
46; CHECK-LABEL: @test1(
47; CHECK-NEXT:    switch i32 %V, label %infloop [
48; CHECK-NEXT:    i32 4, label %A
49; CHECK-NEXT:    i32 17, label %B
50; CHECK-NEXT:    i32 18, label %B
51; CHECK-NEXT:    i32 42, label %D
52; CHECK-NEXT:    ]
53; CHECK:       A:
54; CHECK-NEXT:    call void @foo1()
55; CHECK-NEXT:    ret void
56; CHECK:       B:
57; CHECK-NEXT:    call void @foo2()
58; CHECK-NEXT:    ret void
59; CHECK:       D:
60; CHECK-NEXT:    call void @foo4()
61; CHECK-NEXT:    ret void
62; CHECK:       infloop:
63; CHECK-NEXT:    br label %infloop
64}
65
66