Home | History | Annotate | Download | only in SimplifyCFG
      1 ; RUN: opt < %s -simplifycfg -S | FileCheck %s
      2 
      3 ; CHECK-NOT: switch
      4 
      5 ; Test normal folding
      6 define i32 @test1() {
      7         switch i32 5, label %Default [
      8                  i32 0, label %Foo
      9                  i32 1, label %Bar
     10                  i32 2, label %Baz
     11                  i32 5, label %TheDest
     12         ]
     13 Default:                ; preds = %0
     14         ret i32 -1
     15 Foo:            ; preds = %0
     16         ret i32 -2
     17 Bar:            ; preds = %0
     18         ret i32 -3
     19 Baz:            ; preds = %0
     20         ret i32 -4
     21 TheDest:                ; preds = %0
     22         ret i32 1234
     23 }
     24 
     25 ; Test folding to default dest
     26 define i32 @test2() {
     27         switch i32 3, label %Default [
     28                  i32 0, label %Foo
     29                  i32 1, label %Bar
     30                  i32 2, label %Baz
     31                  i32 5, label %TheDest
     32         ]
     33 Default:                ; preds = %0
     34         ret i32 1234
     35 Foo:            ; preds = %0
     36         ret i32 -2
     37 Bar:            ; preds = %0
     38         ret i32 -5
     39 Baz:            ; preds = %0
     40         ret i32 -6
     41 TheDest:                ; preds = %0
     42         ret i32 -8
     43 }
     44 
     45 ; Test folding all to same dest
     46 define i32 @test3(i1 %C) {
     47         br i1 %C, label %Start, label %TheDest
     48 Start:          ; preds = %0
     49         switch i32 3, label %TheDest [
     50                  i32 0, label %TheDest
     51                  i32 1, label %TheDest
     52                  i32 2, label %TheDest
     53                  i32 5, label %TheDest
     54         ]
     55 TheDest:                ; preds = %Start, %Start, %Start, %Start, %Start, %0
     56         ret i32 1234
     57 }
     58 
     59 ; Test folding switch -> branch
     60 define i32 @test4(i32 %C) {
     61         switch i32 %C, label %L1 [
     62                  i32 0, label %L2
     63         ]
     64 L1:             ; preds = %0
     65         ret i32 0
     66 L2:             ; preds = %0
     67         ret i32 1
     68 }
     69 
     70 ; Can fold into a cond branch!
     71 define i32 @test5(i32 %C) {
     72         switch i32 %C, label %L1 [
     73                  i32 0, label %L2
     74                  i32 123, label %L1
     75         ]
     76 L1:             ; preds = %0, %0
     77         ret i32 0
     78 L2:             ; preds = %0
     79         ret i32 1
     80 }
     81 
     82