| Dan Gohman | 4a63fad | 2010-08-14 00:29:42 +0000 | [diff] [blame] | 1 | ; RUN: opt -S -simplifycfg < %s | FileCheck %s |
| 2 | |
| 3 | ; SimplifyCFG should eliminate redundant indirectbr edges. |
| 4 | |
| 5 | ; CHECK: indbrtest0 |
| 6 | ; CHECK: indirectbr i8* %t, [label %BB0, label %BB1, label %BB2] |
| 7 | ; CHECK: %x = phi i32 [ 0, %BB0 ], [ 1, %entry ] |
| 8 | |
| 9 | declare void @foo() |
| 10 | declare void @A() |
| 11 | declare void @B(i32) |
| 12 | declare void @C() |
| 13 | |
| 14 | define void @indbrtest0(i8** %P, i8** %Q) { |
| 15 | entry: |
| 16 | store i8* blockaddress(@indbrtest0, %BB0), i8** %P |
| 17 | store i8* blockaddress(@indbrtest0, %BB1), i8** %P |
| 18 | store i8* blockaddress(@indbrtest0, %BB2), i8** %P |
| 19 | call void @foo() |
| 20 | %t = load i8** %Q |
| 21 | indirectbr i8* %t, [label %BB0, label %BB1, label %BB2, label %BB0, label %BB1, label %BB2] |
| 22 | BB0: |
| 23 | call void @A() |
| 24 | br label %BB1 |
| 25 | BB1: |
| 26 | %x = phi i32 [ 0, %BB0 ], [ 1, %entry ], [ 1, %entry ] |
| 27 | call void @B(i32 %x) |
| 28 | ret void |
| 29 | BB2: |
| 30 | call void @C() |
| 31 | ret void |
| 32 | } |
| 33 | |
| 34 | ; SimplifyCFG should convert the indirectbr into a directbr. It would be even |
| 35 | ; better if it removed the branch altogether, but simplifycfdg currently misses |
| 36 | ; that because the predecessor is the entry block. |
| 37 | |
| 38 | ; CHECK: indbrtest1 |
| 39 | ; CHECK: br label %BB0 |
| 40 | |
| 41 | define void @indbrtest1(i8** %P, i8** %Q) { |
| 42 | entry: |
| 43 | store i8* blockaddress(@indbrtest1, %BB0), i8** %P |
| 44 | call void @foo() |
| 45 | %t = load i8** %Q |
| 46 | indirectbr i8* %t, [label %BB0, label %BB0] |
| 47 | BB0: |
| 48 | call void @A() |
| 49 | ret void |
| 50 | } |
| 51 | |
| Dan Gohman | 250b754 | 2010-08-16 14:41:14 +0000 | [diff] [blame^] | 52 | ; SimplifyCFG should notice that BB0 does not have its address taken and |
| 53 | ; remove it from entry's successor list. |
| 54 | |
| 55 | ; CHECK: indbrtest2 |
| 56 | ; CHECK: entry: |
| 57 | ; CHECK-NEXT: unreachable |
| 58 | |
| 59 | define void @indbrtest2(i8* %t) { |
| 60 | entry: |
| 61 | indirectbr i8* %t, [label %BB0, label %BB0] |
| 62 | BB0: |
| 63 | ret void |
| 64 | } |