Marcello Maggioni | 5bbe3df | 2014-10-14 01:58:26 +0000 | [diff] [blame^] | 1 | ; RUN: opt < %s -simplifycfg -S | FileCheck %s |
| 2 | |
| 3 | ; int foo1_with_default(int a) { |
| 4 | ; switch(a) { |
| 5 | ; case 10: |
| 6 | ; return 10; |
| 7 | ; case 20: |
| 8 | ; return 2; |
| 9 | ; } |
| 10 | ; return 4; |
| 11 | ; } |
| 12 | |
| 13 | define i32 @foo1_with_default(i32 %a) { |
| 14 | ; CHECK-LABEL: @foo1_with_default |
| 15 | ; CHECK: %switch.selectcmp = icmp eq i32 %a, 20 |
| 16 | ; CHECK-NEXT: %switch.select = select i1 %switch.selectcmp, i32 2, i32 4 |
| 17 | ; CHECK-NEXT: %switch.selectcmp1 = icmp eq i32 %a, 10 |
| 18 | ; CHECK-NEXT: %switch.select2 = select i1 %switch.selectcmp1, i32 10, i32 %switch.select |
| 19 | entry: |
| 20 | switch i32 %a, label %sw.epilog [ |
| 21 | i32 10, label %sw.bb |
| 22 | i32 20, label %sw.bb1 |
| 23 | ] |
| 24 | |
| 25 | sw.bb: |
| 26 | br label %return |
| 27 | |
| 28 | sw.bb1: |
| 29 | br label %return |
| 30 | |
| 31 | sw.epilog: |
| 32 | br label %return |
| 33 | |
| 34 | return: |
| 35 | %retval.0 = phi i32 [ 4, %sw.epilog ], [ 2, %sw.bb1 ], [ 10, %sw.bb ] |
| 36 | ret i32 %retval.0 |
| 37 | } |
| 38 | |
| 39 | ; int foo1_without_default(int a) { |
| 40 | ; switch(a) { |
| 41 | ; case 10: |
| 42 | ; return 10; |
| 43 | ; case 20: |
| 44 | ; return 2; |
| 45 | ; } |
| 46 | ; __builtin_unreachable(); |
| 47 | ; } |
| 48 | |
| 49 | define i32 @foo1_without_default(i32 %a) { |
| 50 | ; CHECK-LABEL: @foo1_without_default |
| 51 | ; CHECK: %switch.selectcmp = icmp eq i32 %a, 10 |
| 52 | ; CHECK-NEXT: %switch.select = select i1 %switch.selectcmp, i32 10, i32 2 |
| 53 | ; CHECK-NOT: %switch.selectcmp1 |
| 54 | entry: |
| 55 | switch i32 %a, label %sw.epilog [ |
| 56 | i32 10, label %sw.bb |
| 57 | i32 20, label %sw.bb1 |
| 58 | ] |
| 59 | |
| 60 | sw.bb: |
| 61 | br label %return |
| 62 | |
| 63 | sw.bb1: |
| 64 | br label %return |
| 65 | |
| 66 | sw.epilog: |
| 67 | unreachable |
| 68 | |
| 69 | return: |
| 70 | %retval.0 = phi i32 [ 2, %sw.bb1 ], [ 10, %sw.bb ] |
| 71 | ret i32 %retval.0 |
| 72 | } |