1 ; Extract the 'if', 'then', and 'else' blocks into the same function.
2 ; RUN: echo 'foo if;then;else' > %t
3 ; Make sure we can still extract a single basic block
4 ; RUN: echo 'foo end' >> %t
5 ; RUN: echo 'bar bb14;bb20' >> %t
6 ; RUN: opt -S -extract-blocks -extract-blocks-file=%t %s | FileCheck %s
11 ; The diamond will produce an i32 value, make sure we account for that.
12 ; CHECK: [[RES_VAL_ADDR:%[^ ]*]] = alloca i32
13 ; CHECK-NEXT: br label %[[FOO_DIAMOND_LABEL:.*$]]
15 ; The if-then-else blocks should be in just one function.
16 ; CHECK: [[FOO_DIAMOND_LABEL]]:
17 ; CHECK: call void [[FOO_DIAMOND:@[^(]*]](i32 %arg1, i32 %arg, i32* [[RES_VAL_ADDR]])
18 ; CHECK-NEXT: [[RES_VAL:%[^ ]*]] = load i32, i32* [[RES_VAL_ADDR]]
19 ; Then it should directly jump to end.
20 ; CHECK: br label %[[FOO_END_LABEL:.*$]]
22 ; End should have been extracted into its own function.
23 ; CHECK: [[FOO_END_LABEL]]:
24 ; CHECK: [[CMP:%[^ ]*]] = call i1 [[FOO_END:@[^(]*]](i32 [[RES_VAL]], i32 %arg)
25 ; CHECK-NEXT: br i1 [[CMP]], label %ret0, label %ret1
26 define i32 @foo(i32 %arg, i32 %arg1) {
28 %tmp5 = icmp sgt i32 %arg, 0
29 %tmp8 = icmp sgt i32 %arg1, 0
30 %or.cond = and i1 %tmp5, %tmp8
31 br i1 %or.cond, label %then, label %else
34 %tmp12 = shl i32 %arg1, 2
35 %tmp13 = add nsw i32 %tmp12, %arg
39 %tmp22 = mul nsw i32 %arg, 3
40 %tmp24 = sdiv i32 %arg1, 6
41 %tmp25 = add nsw i32 %tmp24, %tmp22
45 %tmp.0 = phi i32 [ %tmp13, %then ], [ %tmp25, %else ]
46 %and0 = and i32 %tmp.0, %arg
47 %cmp1 = icmp slt i32 %and0, 0
48 br i1 %cmp1, label %ret0, label %ret1
59 ; Check that we extracted bb14 and bb20 in their own (shared) function.
61 ; CHECK: br i1 %or.cond, label %bb9, label %[[BAR_DIAMOND_LABEL:.*$]]
63 ; CHECK: [[BAR_DIAMOND_LABEL]]:
64 ; CHECK: [[CMP:%[^ ]*]] = call i1 [[BAR_DIAMOND:@[^(]*]](i32 %arg1, i32 %arg, i32*
65 ; CHECK: br i1 [[CMP]], label %bb26, label %bb30
66 define i32 @bar(i32 %arg, i32 %arg1) {
68 %tmp5 = icmp sgt i32 %arg, 0
69 %tmp8 = icmp sgt i32 %arg1, 0
70 %or.cond = and i1 %tmp5, %tmp8
71 br i1 %or.cond, label %bb9, label %bb14
74 %tmp12 = shl i32 %arg1, 2
75 %tmp13 = add nsw i32 %tmp12, %arg
79 %0 = and i32 %arg1, %arg
80 %1 = icmp slt i32 %0, 0
81 br i1 %1, label %bb20, label %bb26
84 %tmp22 = mul nsw i32 %arg, 3
85 %tmp24 = sdiv i32 %arg1, 6
86 %tmp25 = add nsw i32 %tmp24, %tmp22
90 %tmp29 = sub nsw i32 %arg, %arg1
93 bb30: ; preds = %bb26, %bb20, %bb9
94 %tmp.0 = phi i32 [ %tmp13, %bb9 ], [ %tmp25, %bb20 ], [ %tmp29, %bb26 ]
98 ; Check that we extracted the three asked basic blocks.
99 ; CHECK: [[FOO_DIAMOND]]
101 ; Make sure the function doesn't end in the middle of the
102 ; list of the blocks we are checking.
106 ; The name of the if block is weird because it had to be split
107 ; since it was the name of the entry of the original function.
116 ; Check that we extracted the two asked basic blocks.
117 ; CHECK: [[BAR_DIAMOND]]