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